JS: Iterator.prototype.every
(new in ECMAScript 2025)
iterator.every(f)-
- Return
trueif the function f returntruefor every yield in Iterator Object iterator. - As soon as f return
false, exit the iteration and returnfalse, and set the iterator to no more yield.
f is passed args: currentElement, currentIndex.
similar to Array.prototype.every
// define a generator function function* gf() { for (let x of [0, 1, 2, 3]) yield x; } // check if every item is less than 5 console.assert( gf().every((x) => x < 5), ); // check if every item is less than 3 console.assert( gf().every((x) => x < 3) === false, ); - Return