• Find the index of the last occurrence of a value in an array.

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array-like object to search.

    • value: T

      The value to locate in the array. Values are compared using strict === equality.

    • start: number = -1

      The index of the first element in the range to be searched, inclusive. The default value is -1. Negative values are taken as an offset from the end of the array.

    • stop: number = 0

      The index of the last element in the range to be searched, inclusive. The default value is 0. Negative values are taken as an offset from the end of the array.

    Returns number

    The index of the last occurrence of the value, or -1 if the value is not found.

    Notes

    If start < stop the search will wrap at the front of the array.

    Complexity

    Linear.

    Undefined Behavior

    A start or stop which is non-integral.

    Example

    import { ArrayExt } from '@lumino/algorithm';

    let data = ['one', 'two', 'three', 'four', 'one'];
    ArrayExt.lastIndexOf(data, 'red'); // -1
    ArrayExt.lastIndexOf(data, 'one'); // 4
    ArrayExt.lastIndexOf(data, 'one', 1); // 0
    ArrayExt.lastIndexOf(data, 'two', 0); // -1
    ArrayExt.lastIndexOf(data, 'two', 0, 1); // 1