数组方法reduce的使用

基础使用:

function total(array){

var sum=array.reduce( function (pre,curr){

return pre+curr

},初始值)

return sum;

}

 

console.log(  total([1,2,3,4]) );//10

posted @ 2022-03-31 20:15  Chiffon1996  阅读(34)  评论(0)    收藏  举报