coderef

Iterator methodsBaseline · Newly available

The Iterator object is an abstract base for objects that implement the iterator protocol. It provides methods common to built-in iterators, such as filter(), find(), map(), and reduce(). You can also use the static method Iterator.from() to convert an existing iterable into an Iterator.

Works in the latest version of every major browser, but older devices may not support it yet. Baseline since Mar 31, 2025.

Browser support

DesktopChrome
1–121Not supported
122+Supportedsince Feb 20, 2024
Current: 155
Edge
12–121Not supported
122+Supportedsince Feb 23, 2024
Current: 154
Firefox
1–130Not supported
131+Supportedsince Oct 1, 2024
Current: 157
Safari
1–18.3Not supported
18.4+Supportedsince Mar 31, 2025
Current: 27
MobileChrome Android
18–121Not supported
122+Supportedsince Feb 20, 2024
Current: 155
Firefox Android
4–130Not supported
131+Supportedsince Oct 1, 2024
Current: 157
Safari iOS
1–18.3Not supported
18.4+Supportedsince Mar 31, 2025
Current: 27

How to use

Every current browser supports this, but it only became Baseline on Mar 31, 2025. Use it as a progressive enhancement, or keep a fallback if you support older devices.

Example

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

const firstEvenSquares = naturals()
  .filter((n) => n % 2 === 0)
  .map((n) => n * n)
  .take(3)
  .toArray(); // [4, 16, 36]

Feature detection

JS · check before using
if ("Iterator" in Iterator || ("prototype" in Iterator && "Iterator" in Iterator.prototype)) {
  // Iterator.Iterator is available
}

Sub-features

Support for each part of the feature (13). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Iterator.Iterator12212213118.412213118.4
Iterator.drop12212213118.412213118.4
Iterator.every12212213118.412213118.4
Iterator.filter12212213118.412213118.4
Iterator.find12212213118.412213118.4
Iterator.flatMap12212213118.412213118.4
Iterator.forEach12212213118.412213118.4
Iterator.from12212213118.412213118.4
Iterator.map12212213118.412213118.4
Iterator.reduce12212213118.412213118.4
Iterator.some12212213118.412213118.4
Iterator.take12212213118.412213118.4
Iterator.toArray12212213118.412213118.4