get all values from array of objects javascript code example
Example 1: js get all values of object
Object.values(object1)
Example 2: array objects to array of one property
let result = objArray.map(a => a.foo);
Example 3: get all id from array of objects javascript
function getFields(input, field) {
var output = [];
for (var i=0; i < input.length ; ++i)
output.push(input[i][field]);
return output;
}
var result = getFields(objArray, "foo");
Example 4: 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);