The array or array like object of elements to be searched.
A function that accepts up to three arguments of type ArrPredicateCallbackFn or ArrPredicateCallbackFn2. The predicate function is called for each element in the thArray until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
Optional
thisArg: anyA value to use as this when executing callbackFn. Defaults to the array if not provided.
The index of the first element in the array that passes the test. Otherwise, -1.
The arrFindIndex() method returns the index of the first element in an array that satisfies the provided testing function. If no elements satisfy the testing function, -1 is returned.
The arrFindIndex() is an iterative method. It calls a provided callbackFn function once for each element in an array in ascending-index order, until callbackFn returns a truthy value. arrFindIndex() then returns the index of that element and stops iterating through the array. If
callbackFn
never returns a truthy value, arrFindIndex() returns -1.callbackFn
is invoked for every index of the array, not just those with assigned values. Empty slots in sparse arrays behave the same as undefined.arrFindIndex() 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 arrFindIndex() began.callbackFn
to be invoked on them again. If an existing, yet-unvisited element of the array is changed bycallbackFn
, its value passed to thecallbackFn
will be the value at the time that element gets visited. Deleted elements are visited as if they were undefined.Since
0.8.0
Example