make object from array code example
Example 1: js array into object
const names = ['Alex', 'Bob', 'Johny', 'Atta'];
const obj = Object.assign({}, names);
console.log(obj);
Example 2: 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 }), {})
{red: 10, blue: 20, green: 30}
Example 3: js array to object with keys
const arr = ['a','b','c'];
const res = arr.reduce((a,b)=> (a[b]='',a),{});
console.log(res)
Example 4: how to get array from object in javascript
let result = objArray.map(({ foo }) => foo)