Function findLastIndex

Finds the index of the last element in the source array that satisfies the provided predicate function.

Returns -1 if no element satisfies the predicate.

const findLastPositiveIndex = findLastIndex((x: number) => x > 0);
const a = findLastPositiveIndex([1, 2, 3]); // 2
const b = findLastPositiveIndex([-1, 0, -2]); // -1
  • Type Parameters

    • Item

    Parameters

    • predicate: ((item: Item) => boolean)
        • (item): boolean
        • Parameters

          Returns boolean

    Returns ((source: readonly Item[]) => number)

      • (source): number
      • Parameters

        • source: readonly Item[]

        Returns number