const newArray = [
{
weight:20,
total:5
},
{
weight:10,
total:3
}
]
let {weight,total}= newArray.reduce((prev,items)=>{
prev.weight+=Number(items.weight)
prev.total+=Number(items.total)
return prev
},{weight:0,total:0})
console.log(weight,total) // 30 8
array.reduce() 计算合计值
最新推荐文章于 2024-07-09 17:19:05 发布