get property from array of objects javascript code example

Example 1: get array of all property in object array

objArray = [ { foo: 1, bar: 2}, { foo: 3, bar: 4}, { foo: 5, bar: 6} ];
let result = objArray.map(a => a.foo); //[1,3,5]
//OR
let result = objArray.map(({ foo }) => foo) //[1,3,5]

Example 2: find object in array javascript with property

let obj = objArray.find(obj => obj.id == 3);

Example 3: map a property from array of objects javascript

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

Example 4: Getting One Value from an Array of Items

//Getting One Value from an Array of Items or sum of array
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);