JS: Iterator.prototype.find
(new in JS: ECMAScript 2025)
iterator.find(f)
-
- Return the first yield of iterator where the function f returns
true
. - Return undefined if not found.
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.find
// define a generator function function* gf() { for (let x of [5, 3, 4, 3]) yield x; } // get the first even number console.log(gf().find((x, i) => (x % 2 === 0)) === 4); // true // get the first yield that is 9 console.log(gf().find((x, i) => (x === 9)) === undefined); // true
- Return the first yield of iterator where the function f returns
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