iterator.reduce(callback, initialValue) walks each value and updates a running total (the accumulator). When every value has been used, the final accumulator is returned — a number, a string, an object, or whatever you built.
If you pass an initial value, that is the starting accumulator. If you omit it, the first yielded value becomes the start, and reducing begins with the second value. The method consumes the whole iterator.
Remember
iterator.reduce(callback)
iterator.reduce(callback, initialValue)
with initial → start from that value
without initial → first value is the start
empty + no init → TypeError
Callback gets (accumulator, value, index).
Consumes the whole iterator.
Syntax
Call it on an iterator with a reducer function, and usually with an initial value.
// Iterator helpers (Baseline 2025)
Iterator.prototype.reduce(callbackFn)
Iterator.prototype.reduce(callbackFn, initialValue)
// callbackFn : (accumulator, value, index) => nextAccumulator
// initialValue : optional starting accumulator
// returns : the final accumulated value
Parameters
Parameter
Description
callbackFn
Required. Called for each value (after the start is chosen). Return the next accumulator. It receives accumulator, value, and index.
initialValue
Optional. The starting accumulator. If omitted, the first yielded value is used instead, and reducing starts at the second value.
Return Value
Return Value
Description
accumulated value
Whatever your callback builds: often a number or string, but it can be any type. If the iterator is empty and you did not pass initialValue, JavaScript throws a TypeError.
JavaScript Examples
Example 1 — Sum Every Value With an Initial 0
Add 1 through 5 using reduce() with a starting total of 0.
The Try It page first checks that iterator.reduce() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Start at 0. The initial accumulator is 0.
Add each value. The callback returns acc + n for 1, 2, 3, 4, and 5.
Final total. 0 + 1 + 2 + 3 + 4 + 5 equals 15.
Example 2 — Reduce Without an Initial Value
Let the first number be the starting accumulator, then multiply the rest.
The Try It page first checks that iterator.reduce() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
First value starts. With no initial argument, 2 becomes the first accumulator.
Then multiply. Next comes 3 → 2 * 3 = 6, then 4 → 6 * 4 = 24.
Final result. The product of 2, 3, and 4 is 24.
Example 3 — Build a String From Values
Use reduce() to glue numbers into one sentence-like string.
JavaScript
const nums = [1, 2, 3].values();
const text = nums.reduce((acc, n, i) => {
if (i === 0) return String(n);
return acc + " then " + n;
}, "");
console.log(text);
The Try It page first checks that iterator.reduce() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Start with "". The initial accumulator is an empty string.
First value. At index 0 the callback returns "1".
Append the rest. Later steps add " then 2" and " then 3".
Compatibility
Browser & Runtime Support
Iterator.prototype.reduce() is an Iterator helper (Baseline Newly available since March 2025). It works in current browsers and in Node.js 22 or newer.
✓ Baseline 2025 · Newly available
iterator.reduce()
Supported in Chrome 122+, Edge 122+, Firefox 131+, Safari 18.4+, Opera 108+ and Node.js 22+. Internet Explorer never got it.
2025Standard since
Google Chrome122+ · Desktop & Mobile
Full support
Microsoft Edge122+ · Chromium based
Full support
Mozilla Firefox131+ · Desktop & Mobile
Full support
Apple Safari18.4+ · macOS & iOS
Full support
Opera108+ · Chromium based
Full support
Samsung Internet26+ · Android
Supported
Android WebView122+ · Chromium based
Supported
Node.js22+ · Server runtime
Supported
DenoRecent versions · JavaScript runtime
Supported
BunRecent versions · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
iterator.reduce()Current browsers
Bottom line: Check support with a typeof test before you use it in older browsers. Prefer chaining helpers and calling toArray() last.
Frequently Asked Questions
It folds every value from an iterator into one accumulated result using your callback. The final accumulator is returned, and the iterator is consumed.
It is strongly recommended. With an initial value, empty iterators are safe and the starting type is clear. Without one, the first value is the start, and an empty iterator throws TypeError.
Three: the current accumulator, the current value, and the index. Return the next accumulator from the callback.
No. It reads the whole iterator before returning. For infinite sources it never finishes. Use take() first if you only want a limited number of values.
The idea matches Array.prototype.reduce(), but it runs on an iterator helper. Feature-detect support in older browsers before you rely on it.