get array from object javascript code example
Example 1: javascript object to array
const numbers = {
one: 1,
two: 2,
};
console.log(Object.values(numbers));
console.log(Object.entries(numbers));
Example 2: javascript object to array
fooArray = Object.entries(fooObj);
fooArray.forEach(([key, value]) => {
console.log(key);
console.log(value);
})
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)