Iterator.prototype.some()
Baseline Newly available
This feature works across the latest devices and browser versions. This feature might not work in older devices or browser versions. It's been available across browsers since March 2025.
The some() method of Iterator instances is similar to Array.prototype.some(): it returns true if it finds an element that satisfies the provided testing function. Otherwise, if the iterator is exhausted without finding such an element, it returns false.
Syntax
some(callbackFn)
Parameters
-
callbackFn - A function to execute for each element produced by the iterator. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise. The function is called with the following arguments:
-
element - The current element being processed.
-
index - The index of the current element being processed.
-
Return value
true if the callback function returns a truthy value for at least one element. Otherwise, false.
Description
some() iterates the iterator and invokes the callbackFn function once for each element. It returns true immediately if the callback function returns a truthy value. Otherwise, it iterates until the end of the iterator and returns false. If some() returns true, the underlying iterator is closed by calling its return() 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() returns true as soon as the first truthy value is found. If the callbackFn always returns a falsy value, the method never returns.
Calling some() always closes the underlying iterator, even if the method early-returns. The iterator is never left in a half-way state.
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)); // true
const isNegative = (x) => x < 0;
console.log(fibonacci().take(10).some(isNegative)); // false
console.log(fibonacci().some(isNegative)); // Never completes
The method closes the iterator after returning.
const seq = fibonacci();
console.log(seq.some(isEven)); // true
console.log(seq.next()); // { value: undefined, done: true }
Specifications
Browser compatibility
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on iOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
some |
122
117–119
|
122
117–119
|
131 |
108
103–105
|
18.4 |
122
117–119
|
131 |
81
78–79
|
18.4 |
26.0
24.0–25.0
|
122
117–119
|
18.4 |
1.1.31 |
1.39 |
22.0.0 |
See also
- Polyfill of
Iterator.prototype.someincore-js - es-shims polyfill of
Iterator.prototype.some IteratorIterator.prototype.every()Iterator.prototype.find()Array.prototype.some()
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator/some