let list = [ { id: 1, price: 2 }, { id: 2, price: 4 }, { id: 3, price: 6 }, { id: 4, price: 8 }, ]; let res= list.reduce((sumData,key,index,arrData)=>{ console.log('a',sumData); // 上⼀次调⽤回调时返回的累积值 console.log('b',key); // 正在处理的元素 console.log('c',index); // 正在处理的当前元素的索引 console.log('d',arrData); //源数组(原数组) return sumData+key.price },0) console.log('res',res)
标签:es6,console,log,sumData,求和,res,price,数组,id From: https://www.cnblogs.com/vhen/p/17325503.html