create object array from object array javascript code example
Example 1: js create object from array
[
{ id: 10, color: "red" },
{ id: 20, color: "blue" },
{ id: 30, color: "green" }
].reduce((acc, cur) => ({ ...acc, [cur.color]: cur.id }), {})
//output:
{red: 10, blue: 20, green: 30}
Example 2: how to get array from object in javascript
let result = objArray.map(({ foo }) => foo)