JS: Iterator.prototype.some

By Xah Lee. Date: .

(new in JS: ECMAScript 2025)

iterator.some(f)
  • Return true if the function f return true for every yield in Iterator iterator.
  • As soon as f return false, exit the iteration and return false, and set the iterator to no more yield.

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.some

// define a generator function
function* gf() {
  for (let x of [5, 4, 8, 6]) yield x;
}

// call method some
console.log(gf().some((x) => x === 8));
// true

// call method some
console.log(gf().some((x) => x === 99) === false);
// true

JavaScript. iterator helpers