Function lastIndexOf

  • This method is like indexOf except that it iterates over elements of array from right to left.

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array to inspect.

    • value: T

      The value to search for.

    • fromIndex: number

      The index to search from.

    Returns number

    Returns the index of the matched value, else -1.

    5.6.0

    lastIndexOf([1, 2, 1, 2], 2)
    // => 3

    // Search from the `fromIndex`.
    lastIndexOf([1, 2, 1, 2], 2, 2)
    // => 1