• Remove the first occurrence of a value from an array.

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array of interest.

    • value: T

      The value to remove from 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 removed value, or -1 if the value is not contained in the array.

    Notes

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

    Complexity

    Linear.

    Example

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

    let data = [0, 12, 23, 39, 14, 12, 75];
    ArrayExt.removeFirstOf(data, 12); // 1
    ArrayExt.removeFirstOf(data, 17); // -1
    ArrayExt.removeFirstOf(data, 39, 3); // -1
    ArrayExt.removeFirstOf(data, 39, 3, 2); // 2