• Find the index of the first 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 = 0

      The index of the first 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.

    • stop: number = -1

      The index of the last 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.

    Returns number

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

    Notes

    If stop < start the search will wrap at the end 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.firstIndexOf(data, 'red'); // -1
    ArrayExt.firstIndexOf(data, 'one'); // 0
    ArrayExt.firstIndexOf(data, 'one', 1); // 4
    ArrayExt.firstIndexOf(data, 'two', 2); // -1
    ArrayExt.firstIndexOf(data, 'two', 2, 1); // 1