Array.prototype.some()
Tests whether at least one element in an array passes a callback test, short-circuiting on the first match.
some(callbackFn)
some(callbackFn, thisArg)- Added in JavaScript ES5
Parameters
| Parameter | Type | Description |
|---|---|---|
$callbackFn | Function | A function to execute for each element. It should return a truthy value to indicate the element passes the test, and a falsy value otherwise. Called with (element, index, array). |
$thisArgoptional | any= undefined | A value to use as this when executing callbackFn. |
Return value
booleanfalse unless callbackFn returns a truthy value for an array element, in which case true is immediately returned.
Errors
Nothing directly, but any exception thrown by callbackFn propagates out of some() and stops iteration.
Changelog
- PHP ES5Introduced as a standard iterative array method.
some() answers a yes/no question about a collection: is there at least one element for which the predicate is truthy? It walks the array from index 0 and returns true the moment the callback returns something truthy, without visiting the rest. If it reaches the end without a match, it returns false.
When to reach for it
Use it whenever you would otherwise write a for loop with a found = true; break; inside. It is the right tool for validation guards ("does this cart contain any out-of-stock item?"), permission checks, and any condition where you only need existence, not the item itself. If you need the matching element rather than a boolean, use a find operation instead.
What trips people up
On an empty array some() returns false, which is usually what you want but is the mirror image of every(). It also skips empty slots in sparse arrays entirely — the callback is never called for a hole, so [, , ,].some(Boolean) is false. Finally, an arrow function with a block body needs an explicit return; forgetting it makes every call return undefined, and the result is always false.
Example
When to use it
- Guard a checkout flow by testing whether any line item is out of stock
- Check whether a user holds any one of several required roles
- Detect whether a form has at least one field with a validation error
- Decide whether to show a "contains errors" banner over a log list
Frequently asked questions
What does some() return on an empty array?
It returns false. With no elements, nothing can satisfy the predicate, so the result is false — the exact opposite of every(), which returns true on an empty array.
Does some() stop early when it finds a match?
Yes. It returns true immediately on the first truthy callback result and does not visit the remaining elements, which makes it cheap on large arrays where matches appear early.
What is the difference between some() and includes()?
includes() compares against a single fixed value using SameValueZero equality, while some() runs an arbitrary predicate, so it can test object properties, ranges, or any custom condition.
More examples
Validating a shopping cart
The first check finds B7 and returns true immediately, so checkout is blocked. The second scans until C3 and reports that a bulk shipping rule applies. Both return plain booleans, ready to use in an if.
const cart = [
{ sku: "A1", qty: 2, inStock: true },
{ sku: "B7", qty: 1, inStock: false },
{ sku: "C3", qty: 5, inStock: true },
];
const blocked = cart.some((item) => !item.inStock);
console.log("checkout blocked:", blocked);
const bulk = cart.some((item) => item.qty >= 5);
console.log("needs bulk shipping:", bulk);some() versus every() on the same data
The two methods are De Morgan duals. "Some failed" and "not every succeeded" produce the same answer, so pick whichever reads more naturally at the call site.
const responses = [200, 200, 500, 200];
console.log(responses.some((s) => s >= 500)); // true — at least one failed
console.log(responses.every((s) => s < 400)); // false — not all succeeded
// Negating one gives the other:
console.log(!responses.every((s) => s < 500)); // true
console.log(!responses.some((s) => s >= 500)); // falseSparse arrays skip holes
The array reports a length of 11, but the callback runs only three times: for index 0, index 2, and the explicitly assigned index 10. Empty slots are not the same as undefined values here.
const sparse = [1, , 3];
sparse[10] = undefined;
let calls = 0;
const result = sparse.some(() => {
calls++;
return false;
});
console.log("length:", sparse.length); // 11
console.log("callback ran:", calls); // 3 — holes were never visited
console.log(result); // false
Discussion