Array.prototype.some()
The existential check, and the mirror of every. It stops at the first success, so it is the cheap way to ask a yes/no question of a large array.
Demo
True as soon as one element passes — the rest are never tested, which makes this cheap on large arrays. The empty case is worth holding next to every: some on an empty array is FALSE, because no element exists that could pass. every on the same empty array is TRUE. The two methods disagree precisely when there is nothing to check.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| callback | Function | yes | Called as callback(element, index, array). Iteration stops the moment it returns truthy. |
| thisArg | any | no (undefined) | Value of `this` inside the callback. Ignored for arrow functions. |
Return value
boolean — True as soon as the callback returns truthy for any element. False for an empty array — there is nothing that could satisfy it.
Common patterns
if (errors.some(e => e.fatal)) { abort(); }
const has = items.some(o => o.id === targetId);
const invalid = fields.some(f => !f.valid);
Examples
Pitfalls
[].some(x => true)
items.length > 0 && items.some(pred)
[1, 2, 3].some(x => { x > 0 })
[1, 2, 3].some(x => x > 0)
items.some(x => { send(x); return done; })
for (const x of items) { send(x); if (done) break; }
When to use
- Asking whether at least one element qualifies
- Matching objects by their contents
- Short-circuiting a check over a large array
- You need the matching element → find
- You need ALL elements to qualify → every
- Matching a plain value → includes
- You want the count → filter().length
Notes
FAQ
Because it asks whether any element satisfies the test, and an empty array has no elements — so nothing can. It is the mirror of every, which is vacuously true on an empty array for the same structural reason.
[].some(x => true) // false [].every(x => false) // true