記錄下
每個單位對應四種項目類型,求出每個單位的項目總分
這是后台返回的數據
let arrData = [ [714.29,999.52, 999, 712.82, 0, 997, 996, 0, 0, 995], [285.43, 0, 0, 285.64, 997, 0, 0, 995.9, 995.8,0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] /* 豎着求總分數 */ let a = arrData[0]; arrData.forEach((item, index) => { sum(item, index) }) function sum(data, index) { if(index > 0) { a = a.map((item, index) => { return item + data[index] }) } return a } console.log(sum(), '總分數')