const packages = [ { id: 1, quantity: 2, price: 10 }, { id: 2, quantity: 3, price: 20 }, { id: 3, quantity: 1, price: 5 } ]; const total = packages.reduce((acc, obj) => acc + obj.price, 0); console.log(total); // 输出 35
const packages = [ { id: 1, quantity: 2, price: 10 }, { id: 2, quantity: 3, price: 20 }, { id: 3, quantity: 1, price: 5 } ]; const total = packages.reduce((acc, obj) => acc + obj.price, 0); console.log(total); // 输出 35