this.data = this.list.reduce((total,per)=>{
total.push({
name:per.keyWrdDsc,
value:per.num1
}}
return total;
},[]);
实例
计算数组元素相加后的总和:
var numbers = [65, 44, 12, 4]; function getSum(total, num) { return total + num; } function myFunction(item) { document.getElementById("demo").innerHTML = numbers.reduce(getSum); }输出结果:
125