array from object js code example
Example 1: javascript object to array
fooArray = Object.entries(fooObj);
fooArray.forEach(([key, value]) => {
console.log(key);
console.log(value);
})
Example 2: object to array javascript
Object.values(obj)
Example 3: 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 4: how to get array from object in javascript
let result = objArray.map(({ foo }) => foo)