求数组对象中某个属性值的总和

let fruit = [  {name: '苹果', price: 5},  {name: '香蕉', price: 4},  {name: '西瓜', price: 3}];
const sum = fruit.reduce((acc, cur) => acc + cur.price, 0);
console.log(sum); // 12

你可能感兴趣的:(前端,javascript)