📅  最后修改于: 2022-03-11 15:02:37.707000             🧑  作者: Mango
var array = [
{item: "Coffee", price: 4},
{item: "Brownie", price: 5},
];
const getSumByKey = (arr, key) => {
return arr.reduce((accumulator, current) => accumulator + Number(current[key]), 0)
}
const total = getSumByKey(array, 'price') // 9