计算数组对象中某个字段的和

export function sumKey(arr, key) {

​    let result = 0;

​    for (let i = 0; i < arr.length; i++) {

​        result += Number(arr[i][key]);// 点开看 有两个值

​    }

​    return result;

}



const settlement_money_all = sumKey(machine_list, 'settlement_money');

const extra_charges_money_all = sumKey(machine_list, 'extra_charges_money');

const final_settlement_money_all = sumKey(machine_list, 
posted @ 2020-09-17 15:46  小蜗蜗蜗牛^o^  阅读(780)  评论(0编辑  收藏  举报