create an array from an object 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: converting object to array in js

const numbers = {
  one: 1,
};

const objectArray = Object.entries(numbers);

objectArray.forEach(([key, value]) => {
  console.log(key); // 'one'
  console.log(value); // 1
});

Example 3: js array

const users = ["Mark", "Greg"];

Example 4: javascript to array

Array.from("Hello"); // ["H", "e", "l", "l", "o"]