js reduce语法

<script>
  let buf = [10, 110, 20, 120, 30, 130];
  // value记录上次结果
  let mapBuf = buf.reduce(function(value, n) {
    console.log(value, n);
    return 100 + n;
  }, 0)

  console.log(mapBuf);
</script>

let mapBuf = buf.reduce(function(value, n) {
  console.log(value, n);
  return value + n;
}, 0)

posted @ 2021-07-05 14:24  thomas_blog  阅读(28)  评论(0编辑  收藏  举报