Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท Array

Array.prototype.some()

Reference for JavaScript Array.prototype.some(): check whether at least one element passes a test, short-circuiting, the empty-array result and how it compares to every().

The some() method tests whether at least one element of an array passes a test you provide. It returns true as soon as the callback returns a truthy value for any element, and false if none does.

Use it to answer yes-or-no questions such as "is any item out of stock?" without building a filtered array. It stops looking at the first match.

JavaScript
[1, 3, 8].some((n) => n % 2 === 0); // true

Try it

JS Is there at least one?

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Short-circuiting and every()

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
array.some(callbackFn)
array.some(callbackFn, thisArg)
Name Description
callbackFn Called as callbackFn(element, index, array). Return a truthy value to indicate the element passes.
thisArg Optional. The value used as this inside callbackFn (ignored by arrow functions).

Return value: true if the callback returned a truthy value for at least one element; otherwise false.

Exceptions: a TypeError if callbackFn is not a function.

Usage notes

  • Empty arrays return false, because no element passes. The mirror method every() returns true for an empty array.
  • It stops early. Once one element passes, the remaining elements are not visited, so expensive or side-effecting callbacks may not run for all items.
  • Truthy, not strictly true. Any truthy return counts, but returning a real boolean keeps intent clear.
  • No mutation by itself, though the callback can mutate the array. Avoid that.
  • Holes are skipped, so the callback is never called for empty slots in sparse arrays.
  • Checking for a plain value is simpler with includes(). Use some() when you need a condition.
  • Need the element or its index? Use find() or findIndex().
  • Negation: !array.some(fn) means "none pass". array.every((x) => !fn(x)) means the same.
  • Async callbacks return promises, which are always truthy, so some() would return true immediately. Resolve the results first with Promise.all().

Browser support

Array.prototype.some() is part of ES5 and works in every browser in use today.