
If you have ever written users.filter(...).map(...).slice(0, 10) on a large list, you have paid a tax you probably did not notice: every array method eagerly builds a brand-new array. ES2025 finally gives us a native way out — iterator helpers — and they turn that chain into a lazy pipeline that touches only the values you actually consume.
The hidden cost of a normal array chain
Consider a perfectly ordinary task: grab the names of the first 10 active users out of 50,000.
const names = users
.filter(u => u.active) // builds ~32,000 intermediate objects
.map(u => u.name) // builds another ~32,000 strings
.slice(0, 10); // keeps 10, throws the rest away
Three array allocations, and the chain visits ~82,000 elements to return 10 strings. You needed a handful of names; you materialized tens of thousands of values along the way.
There used to be only two escapes: hand-write a for...of loop, or pull in lodash/fp, ramda, or iter-tools. Both are now largely unnecessary.
The lazy version
Get an iterator with .values() (or call a generator, or use Iterator.from()), then chain the helper methods:
const names = users.values()
.filter(u => u.active) // lazy: returns a new iterator, does no work yet
.map(u => u.name) // lazy
.take(10) // lazy: stops after 10 values
.toArray(); // eager: the ONLY step that allocates
Nothing runs until .toArray(). Then values flow through the whole chain one at a time, and .take(10) short-circuits the source the moment it has 10 results. If the first 10 active users appear within the first 200 entries, the chain visits 200 elements — not 82,000. Only 10 strings are ever created.
The two kinds of helper
The API is split cleanly by when work happens.
- Lazy (returns another iterator):
map,filter,take,drop,flatMap. They wrap the source and do nothing until pulled. - Eager (consumes the iterator, returns a value):
toArray,reduce,forEach,find,some,every.
These methods live on Iterator.prototype, so anything whose prototype chain reaches it gets them for free: array .values(), Set.prototype.values(), Map.prototype.entries(), strings via Symbol.iterator, generators, and Iterator.from(anyIterable).
Iterator.from() is the safe adapter when you are not sure what you have. Pass it a plain iterator-like object that does not inherit the helpers and it wraps it; pass it something that already has them and it returns it unchanged — no double wrapping.
The case array methods simply cannot handle: infinite sources
This is where the feature stops being a micro-optimization and becomes enabling. Array methods require a finite array; iterator helpers can bound an infinite generator with .take():
function* naturalNumbers() {
let n = 1;
while (true) yield n++;
}
const firstFiveEvenSquares = naturalNumbers()
.filter(n => n % 2 === 0)
.map(n => n * n)
.take(5)
.toArray();
// [4, 16, 36, 64, 100]
Instrument the callbacks and the laziness is measurable, not theoretical: .filter runs 10 times (checking 1 through 10), .map runs exactly 5 times (once per even number). An unbounded generator, fully handled, after touching 10 values.
Gotchas that will bite you
- An iterator is single-use. Chaining wraps the source; it does not copy it. The wrapper and the original share one cursor, so interleaving pulls gives surprising results. Hand an iterator to a helper and treat it as owned — never reuse the original.
- Terminal methods drain it. Call
.toArray()twice on the same iterator and the second call returns[]. If you need the data more than once, materialize to an array first, or combine both passes into a single.reduce(). .take()is the brake;.drop()and a never-matching filter are not. On an infinite source,.drop(n)still hangs, and a filter that never matches will pull forever. Only a boundedtake/find/some/everyguarantees termination.- Not always faster on tiny arrays. For a 10-element array you fully consume, eager array methods can edge out the helper machinery thanks to per-value wrapping overhead. The lazy version wins when you consume far less than the source holds, or when the source cannot fit in memory at all. Do not rewrite every
.map()on reflex. - Sync helpers do not work on async generators. The async iterator helpers proposal is still at Stage 2. For
async function*pipelines, keep usingfor await...ofwithbreak, or an async library. - Map gives you values, not entries.
map.values()iterates values; useIterator.from(map)when you want[key, value]pairs.
Support
The proposal reached Stage 4 in late 2024 and shipped in ES2025. It is Baseline newly available as of March 2025: current Chrome/Edge, Firefox 131+, and Safari all support it, as do Node 22 LTS and 24, Deno 2, and Bun 1.1.31+. TypeScript 5.6+ ships the types in lib.es2025.iterator.d.ts; on older Node targets, core-js/proposals/iterator-helpers covers the polyfill.
When to reach for it
- The source is a generator, stream, or infinite sequence.
- You only need a partial result — an early
take,find, orsome. - An early filter discards most of a large dataset.
- You want lazy composition without a runtime dependency and its bundle cost.
Stick with plain array methods for small, in-memory arrays where you need the array back anyway. Old habits are not always wrong — but when the data is large or unbounded, this is the tool that was missing.