例如现在有一个数组{"msg": "success","code": 0,"list": [{ "mealId": 17, "mealName": "蔬菜", "protein": 1, "typeList": null, "df": 1, "cho": 1}, { "mealId": 18, "mealName": "牛排", "protein": 1, "typeList": null, "df": 1, "cho": 1}]}定义 sumCHO / sumProtein / sumDF 如何将数组内 cho / protein / df 根据数组的长度进行相加并赋值呢
1 回答
胡子哥哥
TA贡献1825条经验 获得超6个赞
let choTotal = list.reduce((totle, item) => total + item.cho) let proteinTotal = list.reduce((totle, item) => total + item.protein) let dfTotal = list.reduce((totle, item) => total + item.df)
添加回答
举报
0/150
提交
取消