Favorites

JavaScript Iterator Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Iterator
JavaScript Control Abstraction · ConstructorThis object is supported by most modern browsers, though support in some browsers is unknown.
Updated 28th November 2026

Iterator is the base of every built-in iterator, such as those returned by array.values() or map.entries(). Its helper methods, like map(), filter() and take(), work lazily on any iterator.

Description

An iterator is an object with a next() method that returns { value, done } results one at a time. Arrays, strings, maps, sets and generators all produce iterators, which is how for...of, spread syntax and destructuring read them. The global Iterator is the shared parent of all built-in iterators.

Iterator helpers, available in current browsers, add methods such as map(), filter(), take(), drop(), flatMap(), reduce(), some(), every(), find() and toArray(). Unlike their array equivalents, they are lazy: values are processed only as they are requested, so they work with very large or infinite sequences. Iterator.from() wraps any iterable or iterator-like object.

You can write your own iterator by giving an object a [Symbol.iterator]() method that returns an object with next(), although generator functions are usually the easiest way. Iterators can only be consumed once: after a loop has read all its values, an iterator is exhausted, while an iterable such as an array can create a fresh iterator each time it's looped over.

Creating

Iterator.from(iterable)

Example

function* naturals() {
  let n = 1;
  while (true) yield n++;
}

const firstEvens = naturals()
  .filter(n => n % 2 === 0)
  .map(n => n * 10)
  .take(3)
  .toArray();
console.log(firstEvens);

const it = [1, 2].values();
console.log(it.next(), it.next(), it.next());

Browser Support

The following information will show you the current browser support for the Iterator object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by most modern browsers, though support in some browsers is unknown.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee