Question: I have an array of objects like this

```
const values = [{
    existing_value: 'Headline 56',
    new_value: 'Headline_new56',
  },
  {
    existing_value: 'Headline 59',
    new_value: 'Headline_new59',
  },
]

```

And I want to convert into this form.

```
const newObject = { "Headline 56": "Headline_new56",  "Headline 59": "Headline_new59"}

```

I was thinking something like this could work

```
const newObject = {}

const testvalues = values.map(obj => Object.assign( newObject, obj.existing_value: obj.new_value)) 

```

Syntactically it's not quite right. What is the best way to go about it?

Answer: 
Use Array reduce

```js
const values = [{
    existing_value: 'Headline 56',
    new_value: 'Headline_new56',
  },
  {
    existing_value: 'Headline 59',
    new_value: 'Headline_new59',
  },
];

const obj = values.reduce((a, b) => ({ ...a,
  [b.existing_value]: b.new_value
}), {})

console.log(obj)
```
Extracted from [mozilla webdocs](https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/map#example_mapping_an_array_of_numbers_to_an_array_of_square_roots_2)

```js
const values = [{
        existing_value: 'Headline 56',
        new_value: 'Headline_new56',
    },
    {
        existing_value: 'Headline 59',
        new_value: 'Headline_new59',
    },
];

const newObj = values.map((obj) => {
    var rObj = {};
    rObj[obj.existing_value] = obj.new_value;
    return rObj;
});

console.log(newObj);
```