Get to know MDN better
Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
The forEach() method of Iterator instances is similar to Array.prototype.forEach(): it executes a provided function once for each element produced by the iterator.
A function to execute for each element produced by the iterator. Its return value is discarded. The function is called with the following arguments:
elementThe current element being processed.
indexThe index of the current element being processed.
forEach() iterates the iterator and invokes the callbackFn function once for each element. Unlike most other iterator helper methods, it does not work with infinite iterators, because it is not lazy.
This is equivalent to:
| ECMAScript® 2027 Language Specification # sec-iterator.prototype.foreach |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.