This chapter follows Async iterators and for await..of.
Before ES2025, lazy pipelines often meant generator functions or third-party libraries. Iterator helpers standardize lazy map/filter-style operations on iterator objects returned from iterables.
Support landed in modern engines across 2024–2025; see ECMAScript versions cheat sheet for timing in your target runtimes.
Iterator objects from iterables
Iterator.from(iterable) (and the iterator instance methods below) produce an iterator object—not an Array. Consumption still happens one next() at a time.
const it = Iterator.from([1, 2, 3, 4]);console.log(it.next()); // { value: 1, done: false }Many built-in iterables now expose .values(), .keys(), and .entries() iterator objects with the same helper methods.
Chaining map, filter, and take
Helpers return new iterator objects; nothing runs until something consumes the chain:
const result = Iterator.from([1, 2, 3, 4, 5, 6]) .filter((n) => n % 2 === 0) .map((n) => n * 10) .take(2);
console.log([...result]); // [20, 40]Common instance methods include:
| Method | Role |
|---|---|
.map(fn) |
Transform each value |
.filter(fn) |
Skip values that fail the predicate |
.take(n) |
Stop after n values |
.drop(n) |
Skip the first n values |
.flatMap(fn) |
Map to iterables and flatten one level |
.reduce(fn, initial) |
Fold the remainder of the sequence |
.toArray() |
Materialize remaining values into an array |
.forEach(fn) |
Run side effects while consuming |
.some / .every / .find |
Short-circuiting searches |
Exact names and edge cases follow ECMA-262; unavailable methods mean the runtime has not shipped helpers yet.
Lazy versus array methods
Array map / filter / slice always touch the array protocol and often allocate intermediate arrays. Iterator helpers defer work until the next value is pulled—useful for large or infinite sequences and for chaining without temporary arrays.
When you need random access, sorting in place, or mutating methods, stay with arrays. When you are streaming or composing steps on iterables, helpers fit the iterator model from Iterators in JavaScript.
Infinite or expensive sources
function* naturals() { let n = 1; while (true) yield n++;}
const firstSquares = Iterator.from(naturals()) .map((n) => n * n) .take(5);
console.log(firstSquares.toArray()); // [1, 4, 9, 16, 25]Because take ends the chain, the infinite generator stops receiving next() calls—no need to bake a limit into the generator itself.
Relation to generators and async iteration
Generator functions remain the ergonomic way to author custom sequences. Iterator helpers are the standard way to transform existing iterables in a lazy pipeline. Async iterators use a parallel async-helper proposal path in the language; sync helpers described here apply to sync iterator objects.
That completes the Iteration and Generators series. For asynchronous control flow outside iteration, start with Asynchronous data handling.