JS: Iterator.prototype.some

By Xah Lee. Date: . Last updated: .

(new in ECMAScript 2025)

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

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

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

// call method some
console.assert(
 gf().some((x) => x === 99) === false,
);