iteration

Array.prototype.some

Returns true if the callback returns truthy for at least one element, short-circuiting on the first hit. Reach for it to answer "does anything match?" without walking the full array.

arr.some(callbackFn[, thisArg])

Parameters

Parameter Purpose
callbackFn(element, index, array) Predicate tested against each element
thisArg Value used as `this` inside callbackFn

Examples

console.log([1,2,3].some(n => n > 2));

Logs: true

console.log([1,2,3].some(n => n > 99));

Logs: false

console.log([].some(() => true));

Logs: false (empty arrays are always false)

console.log([{ok:false},{ok:true}].some(o => o.ok));

Logs: true

Gotcha

some on an empty array is false; every on an empty array is true — this is vacuous-truth by design. some short-circuits, so callbacks can have side effects that stop firing after the first match.

Related methods

← All JS array methods · TypeScript vs JavaScript