Answers for "how loop through an array of objects in js"

0

iterate over array of objects javascript

// Sum up a particular property, and calculate its average

const myArray = [{x:100}, {x:200}, {x:300}];

const sum = myArray.map(element => element.x).reduce((a, b) => a + b, 0);
console.log(sum); // 600 = 0 + 100 + 200 + 300

const average = sum / myArray.length;
console.log(average); // 200
Posted by: Guest on January-02-2021

Code answers related to "how loop through an array of objects in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language