javascript extract object from array code example

Example 1: map a property from array of objects javascript

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

Example 2: javascript extract array from object

var obj = {v1: 'v1', v2: 'v2'};
// extract object's values as array
var valuesArray = Object.values(obj);	// ['v1','v2']

Example 3: 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);