The some()
method is an iterative method. It calls a provided callbackFn
function once for each element in an array, until the callbackFn
returns a truthy value. If such an element is found, some()
immediately returns true
and stops iterating through the array. Otherwise, if callbackFn
returns a falsy value for all elements, some()
returns false
. Read the iterative methods section for more information about how these methods work in general.
some()
acts like the "there exists" quantifier in mathematics. In particular, for an empty array, it returns false
for any condition.
callbackFn
is invoked only for array indexes which have assigned values. It is not invoked for empty slots in sparse arrays.
some()
does not mutate the array on which it is called, but the function provided as callbackFn
can. Note, however, that the length of the array is saved before the first invocation of callbackFn
. Therefore:
-
callbackFn
will not visit any elements added beyond the array's initial length when the call to some()
began. - Changes to already-visited indexes do not cause
callbackFn
to be invoked on them again. - If an existing, yet-unvisited element of the array is changed by
callbackFn
, its value passed to the callbackFn
will be the value at the time that element gets visited. Deleted elements are not visited.
Warning: Concurrent modifications of the kind described above frequently lead to hard-to-understand code and are generally to be avoided (except in special cases).
The some()
method is generic. It only expects the this
value to have a length
property and integer-keyed properties.