An Iterator is an object that produces values one at a time. You ask for the next value with next(), and you get an object like { value, done }. When done is true, there are no more values.
An iterable (such as an array, a Map or a string) can create an iterator when you need one, usually through [Symbol.iterator](). Loops like for...of use that protocol for you.
Methods such as map(), filter(), take() and toArray() are Baseline Newly available (2025). They work in current browsers and in Node.js 22 or newer. Always feature-detect in older environments.
Syntax
JavaScript Syntax
Get an iterator, pull values, and use a helper chain:
Ideas every Iterator tutorial in this series builds on:
Idea
Example
Remember
Iterator
it.next()
An object that yields { value, done } one step at a time
Iterable
for (const v of arr)
Anything with [Symbol.iterator]() that can make an iterator
Lazy helpers
it.map(fn)
Transform values only when they are pulled
Iterator.from()
Iterator.from(x)
Make a proper Iterator from an iterable or plain next() object
take() / drop()
it.take(3)
Limit or skip values without building a full array first
toArray()
it.toArray()
Collect remaining values into a new Array
Infinite sources
function* fib()
Generators can go forever; helpers like find() stop early
Compare
Iterator helpers vs Array methods
Many helpers look like array methods. The big difference is when the work happens:
Feature
Array methods
Iterator helpers
When work runs
Usually right away on the whole array
Lazily, when you ask for the next value
Memory
Often builds new arrays at each step
Can avoid big temporary arrays
Infinite data
Not practical
Works with take(), find(), and similar
Starting point
An Array
Any iterator (arrays, maps, generators, ...)
Finish the chain
Already an array
Often call toArray() or loop with for...of
Use array methods when you already have a small array and want a simple style. Use iterator helpers when you want lazy pipelines, or when the source is a generator or another iterator.
Behavior
How an Iterator Works
Pull, do not push
You ask for the next value. The iterator does not dump everything at once. That is why large or infinite sequences are possible.
done means finished
When next() returns { done: true }, stop. The value is usually undefined at that point.
Helpers share the source
A helper such as map() reads from the same underlying iterator. Do not expect to replay the same iterator twice unless you create a new one.
Chain, then collect
A common pattern is .filter(...).map(...).take(n).toArray(). Keep toArray() at the end so earlier steps stay lazy.
Closing early
Some iterators have a return() method. [Symbol.dispose]() calls it so resources can be cleaned up when you stop early.
Practice
Real-Life Uses
Iterators show up everywhere in modern JavaScript. Common uses:
Use
How an Iterator helps
Process without a huge array
Filter and map a stream of values from a Map, a Set or a generator without copying everything first.
Stop early
Use find(), take() or some() on a long or infinite sequence and stop as soon as you have an answer.
Readable pipelines
Chain drop(), filter() and map() so each step has one clear job.
Pair related data
Use Iterator.zip() or zipKeyed() when you want matching positions from several iterables.
Code
JavaScript Examples
Three short programs. Each one prints plain text that is the same every time you run it. Iterator helpers need a current browser or Node.js 22+.
Example 1 — Call next() by Hand
Create an array iterator and pull values with next() until done is true.
JavaScript
const it = ["a", "b"].values();
console.log(JSON.stringify(it.next()));
console.log(JSON.stringify(it.next()));
console.log(JSON.stringify(it.next()));
An Iterator is an object with a next() method that returns { value, done }. Each call gives the next value. When done is true, the sequence is finished.
An iterable can create an iterator (usually with [Symbol.iterator]()). An iterator is the object you pull values from with next(). Arrays are iterable; array.values() returns an iterator.
Helpers are lazy: they do work only when you pull values. That saves memory and lets you stop early with take() or find(), even on infinite generators.
Call array.values() (or keys()/entries()), then chain helpers: [1,2,3].values().map(n => n * 2).toArray(). You can also use Iterator.from(array).
The core helpers (map, filter, take, drop, toArray and friends) are Baseline Newly available since 2025 in current Chrome, Firefox, Safari and Node.js 22+. Newer methods such as concat, zip and chunks need even newer engines — always feature-detect.