JS: Iterator.prototype.every

By Xah Lee. Date: . Last updated: .

(new in ECMAScript 2025)

iterator.every(f)
  • Return true if the function f return true for every yield in Iterator Object iterator.
  • As soon as f return false, exit the iteration and return false, 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,
);