arrObj = [{
title: '序号',
width:60,
},
{
title: '商品编码',
width:80,
}]
//计算对象数组中某个属性合计
countTotal = (arr, keyName) => {
let $total = 0;
$total = arr.reduce(function (total, currentValue, currentIndex, arr){
return currentValue[keyName] ? (total + currentValue[keyName]) : total;
}, 0);
return $total;
}
console.log(countTotal(arrobj, 'width'))
【JS】对象数组根据某个属性求和
最新推荐文章于 2023-11-27 16:36:25 发布