reduce 清單合併

在 JavaScript 1.8引入

reduce(callback[, initialValue) 使用 callback(firstValue, secondValue) 把項目的清單合併成單一的值

var a = [10, 20, 30];

var total = a.reduce(function(first, second) { return first + second; }, 0);

alert(total) // 60