Iterator.prototype.some()
Baseline 2025Newly available
Since March 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Thesome() method ofIterator instances is similar toArray.prototype.some(): it tests whether at least one element produced by the iterator passes the test implemented by the provided function. It returns a boolean value.
In this article
Syntax
some(callbackFn)Parameters
callbackFnA function to execute for each element produced by the iterator. It should return atruthy value to indicate the element passes the test, and afalsy value otherwise. The function is called with the following arguments:
Return value
true if the callback function returns atruthy value for at least one element. Otherwise,false.
Description
some() iterates the iterator and invokes thecallbackFn function once for each element. It returnstrue immediately if the callback function returns a truthy value. Otherwise, it iterates until the end of the iterator and returnsfalse. Ifsome() returnstrue, the underlying iterator is closed by calling itsreturn() method.
The main advantage of iterator helpers over array methods is that they are lazy, meaning that they only produce the next value when requested. This avoids unnecessary computation and also allows them to be used with infinite iterators. With infinite iterators,some() returnstrue as soon as the first truthy value is found. If thecallbackFn always returns a falsy value, the method never returns.
Examples
>Using some()
function* fibonacci() { let current = 1; let next = 1; while (true) { yield current; [current, next] = [next, current + next]; }}const isEven = (x) => x % 2 === 0;console.log(fibonacci().some(isEven)); // trueconst isNegative = (x) => x < 0;console.log(fibonacci().take(10).some(isNegative)); // falseconsole.log(fibonacci().some(isNegative)); // Never completesCallingsome() always closes the underlying iterator, even if the method early-returns. The iterator is never left in a half-way state.
const seq = fibonacci();console.log(seq.some(isEven)); // trueconsole.log(seq.next()); // { value: undefined, done: true }Specifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-iterator.prototype.some> |