JS: Iterator.prototype.forEach
(new in JS: ECMAScript 2025)
iterator.forEach(f)
-
Normally you can use this method on any Iterable, because all standard iterable objects are also Iterator.
- f is given args:
- currentElement
- currentIndex
similar to JS: Array.prototype.forEach
// define a generator function function* gf() { for (let x of Array(5).fill(0)) yield x; } // create a generator (is an iterable) const gg = gf(); // use method forEach const hh = gg.forEach((x, i) => console.log(x, i)); /* 0 0 0 1 0 2 0 3 0 4 */ console.log(hh === undefined); // true
JavaScript. iterator helpers
- JS: Iterator.prototype.map
- JS: Iterator.prototype.forEach
- JS: Iterator.prototype.filter
- JS: Iterator.prototype.reduce
- JS: Iterator.prototype.take
- JS: Iterator.prototype.drop
- JS: Iterator.prototype.every
- JS: Iterator.prototype.some
- JS: Iterator.prototype.find
- JS: Iterator.prototype.flatMap
- JS: Iterator.prototype.toArray