get array from object javascript code example

Example 1: javascript object to array

//ES6 Object to Array

const numbers = {
  one: 1,
  two: 2,
};

console.log(Object.values(numbers));
// [ 1, 2 ]

console.log(Object.entries(numbers));
// [ ['one', 1], ['two', 2] ]

Example 2: javascript object to array

//Supposing fooObj to be an object

fooArray = Object.entries(fooObj);

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

Example 3: js get all values of object

Object.values(object1)

Example 4: how to get array from object in javascript

let result = objArray.map(({ foo }) => foo)

Example 5: map a property from array of objects javascript

var result = objArray.map(function(a) {return a.foo;});

Example 6: return an object from an array javascript

myArray.find(item => item.isAstronaut)