Standard built-ins

Iterator.prototype.reduce()

Try the free JavaScript compiler

Consumes the sequence into an accumulator. Without an initial value, an empty sequence throws TypeError.

Formal Syntax & Structure

javascript syntaxjavascript
iterator.reduce(reducer[, initialValue])

Parameters & Attributes

NameTypeDescription
reducerfunctionAccumulator callback.
initialValueanyOptional starting accumulator.

Return Value

any

Result of the operation.

Working Example

Example Snippetjavascript
console.log(JSON.stringify(Iterator.from([1,2,3]).reduce((a,b)=>a+b,0)));
JavaScript Reference