定义

reduce方法对数组中的每个元素执行一个自定义的reducer函数,并将其结果汇总为单个返回值

  1. const arr = [1, 2, 3, 4, 5]
  2. const reducer = (acc, cur) => { acc + cur }
  3. arr.reduce(reducer)