1var array = [
2 {name: "Peter", age: 43},
3 {name: "John", age: 32},
4 {name: "Jake", age: 21}
5];
6
7array.reduce(function(sum, current) {
8 return sum + current.age;
9}, 0); // 43 + 32 + 21 = 96
1var array = [
2 {item: "Coffee", price: 4},
3 {item: "Brownie", price: 5},
4];
5
6const getSumByKey = (arr, key) => {
7 return arr.reduce((accumulator, current) => accumulator + Number(current[key]), 0)
8}
9
10const total = getSumByKey(array, 'price') // 9