Iterator
The Iterator global object is the abstract base class of every built-in iterator, and its prototype supplies lazy helper methods such as .map(), .filter(), and .take(). Array, Map, Set, and string iterators, along with generator objects, all inherit from Iterator.prototype, so they share these helpers:
> const steps = ["install", "build", "test"].values();
undefined
> steps instanceof Iterator
true
> steps.map((step) => step.toUpperCase()).toArray()
[ 'INSTALL', 'BUILD', 'TEST' ]
The helpers produce values only when something asks for the next one. That makes them work on infinite sequences, and it means a chain such as .map().filter() doesn’t build intermediate arrays the way Array methods do.
The Iterator global, Iterator.from(), and the helper methods were added in ES2025. They’re Baseline Newly available since 2025, and supported in Node.js 22 and later. Iterator.concat() was added in ES2026. It’s Baseline Newly available since 2026, and supported in Node.js 26 and later.
Syntax
Iterator can’t be called or constructed directly. A class extends it and supplies a next() method, or Iterator.from() wraps an existing iterable or iterator:
class <Name> extends Iterator {
next() {
<statements>
}
}
Iterator.from(<object>)
| Parameter | Description |
|---|---|
object |
An iterable, or an object with a next() method that follows the iterator protocol |
Iterator.from() returns the object’s iterator unchanged when it already inherits from Iterator.prototype, and wraps it in a new Iterator otherwise. Calling Iterator() without new throws a TypeError, and so does new Iterator().
Key Static Methods and Properties
| Member | Kind | Description |
|---|---|---|
Iterator.from() |
Static method | Returns an Iterator for an iterable or an iterator-like object, so it gains the helper methods (ES2025) |
Iterator.concat() |
Static method | Returns an iterator that yields the values of each iterable in turn (ES2026) |
Iterator.zip(), Iterator.zipKeyed() |
Static method | Return an iterator that combines several iterables position by position, into arrays or into objects (Stage 4) |
Key Instance Methods and Properties
| Member | Kind | Description |
|---|---|---|
.map(), .filter(), .flatMap() |
Instance method | Return a new iterator that transforms, selects, or flattens values as they’re requested (ES2025) |
.take(), .drop() |
Instance method | Return a new iterator that stops after a number of values or skips that many first (ES2025) |
.toArray() |
Instance method | Collects every remaining value into a new array (ES2025) |
.reduce(), .forEach() |
Instance method | Consume the iterator to build one result or to run a function on each value (ES2025) |
.some(), .every(), .find() |
Instance method | Test values until the answer is known, then close the iterator (ES2025) |
.chunks(), .windows() |
Instance method | Return an iterator of fixed-size groups or of overlapping sliding windows (Stage 4) |
.includes(), .join() |
Instance method | Check whether a value appears, or concatenate the values into a string (Stage 4) |
[Symbol.iterator]() |
Instance method | Returns the iterator itself, so every iterator also works in for...of |
Note: Iterator.zip(), Iterator.zipKeyed(), .chunks(), .windows(), .includes(), and .join() reached Stage 4 in 2026 and are expected in ES2027. As of November 2026, Firefox ships all six and Chrome ships all but .chunks() and .windows(). Stable Safari and Node.js 26 don’t ship any of them yet, so they have Limited availability in Baseline terms.
Examples
A support desk hands out ticket numbers from an endless generator, and even numbers go to a second queue. Because the helpers are lazy, .take() stops the infinite sequence after three matches:
> function* ticketIds() {
… let id = 1000;
… while (true) {
… yield id++;
… }
… }
undefined
> ticketIds().filter((id) => id % 2 === 0).take(3).toArray()
[ 1000, 1002, 1004 ]
Step through that chain to watch .toArray() pull each value through .take(3) and .filter() from the generator, one request at a time:
An older database driver returns a cursor object with only a next() method, so it has no helpers. Iterator.from() wraps it in a real iterator:
> const legacyCursor = {
… rows: ["ada", "grace", "linus"],
… index: 0,
… next() {
… const done = this.index >= this.rows.length;
… return { value: this.rows[this.index++], done };
… },
… };
undefined
> legacyCursor.map
undefined
> Iterator.from(legacyCursor).map((name) => name.toUpperCase()).toArray()
[ 'ADA', 'GRACE', 'LINUS' ]
A settings screen lists the built-in themes followed by the user’s own, stored in two Set objects. Iterator.concat() walks both without copying them into a combined array first:
> const builtInThemes = new Set(["light", "dark"]);
undefined
> const customThemes = new Set(["solarized"]);
undefined
> Iterator.concat(builtInThemes, customThemes).toArray()
[ 'light', 'dark', 'solarized' ]
Common Gotchas
An iterator is single-use. Once a helper such as .toArray() has consumed it, it has nothing left to give:
> const queue = ["lint", "test"].values();
undefined
> queue.toArray()
[ 'lint', 'test' ]
> queue.toArray()
[]
Arrays are iterable but aren’t iterators, so they don’t have the helper methods. Calling .values() first returns an array iterator that does:
> [1, 2, 3].take(2)
Uncaught TypeError: [1,2,3].take is not a function
> [1, 2, 3].values().take(2).toArray()
[ 1, 2 ]
Related Resources
Course
JavaScript Loops for Pythonistas
Port a small Python report to JavaScript one loop at a time, and learn where your Python loop habits break in JavaScript, often silently, and what JavaScript developers write instead.
For additional information on related topics, take a look at the following resources:
- JavaScript Arrays for Pythonistas (Course)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 12, 2026