A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/forEach below:

Iterator.prototype.forEach() - JavaScript | MDN

Iterator.prototype.forEach()

Baseline 2025

Newly available

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.

Syntax Parameters
callbackFn

A function to execute for each element produced by the iterator. Its return value is discarded. The function is called with the following arguments:

element

The current element being processed.

index

The index of the current element being processed.

Return value

undefined.

Description

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.

Examples Using forEach()
new Set([1, 2, 3]).values().forEach((v) => console.log(v));

// Logs:
// 1
// 2
// 3

This is equivalent to:

for (const v of new Set([1, 2, 3]).values()) {
  console.log(v);
}
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4