findIndex method

int findIndex(
  1. bool fn(
    1. E element,
    2. int index,
    3. JsArray<E> array
    )
)

The findIndex() 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. findIndex() then returns the index of that element and stops iterating through the array. If callbackFn never returns a truthy value, findIndex() 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.

findIndex() 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 findIndex() 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 visited as if they were undefined.

Implementation

int findIndex(bool Function(E element, int index, JsArray<E> array) fn) =>
    jsu.callMethod(this, 'findIndex', [allowInterop(fn)]);