get values from array of objects javascript code example
Example 1: get all entries in object as array hjs
const object1 = {
a: 'somestring',
b: 42
};
for (let [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 2: array objects to array of one property
let result = objArray.map(a => a.foo);
Example 3: object get array of values
const data = {
"2015": {
"year": 2015,
"cover": {}
}
}
Object.entries(data).forEach(([key, value]) => console.log(key, value));
Example 4: map a property from array of objects javascript
var result = objArray.map(function(a) {return a.foo;});
Example 5: extract value from array of objects javascript
let result = objArray.map(a => a.foo);
Example 6: Getting One Value from an Array of Items
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
var total = numbers.reduce(function(total, current) {
return total + current;
}, 0);
console.log(total);