• Create a slice of an array subject to an optional step.

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array-like object of interest.

    • options: ArrayExt.slice.IOptions = {}

      The options for configuring the slice.

    Returns T[]

    A new array with the specified values.

    Throws

    An exception if the slice step is 0.

    Complexity

    Linear.

    Undefined Behavior

    A start, stop, or step which is non-integral.

    Example

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

    let data = [0, 3, 4, 7, 7, 9];
    ArrayExt.slice(data); // [0, 3, 4, 7, 7, 9]
    ArrayExt.slice(data, { start: 2 }); // [4, 7, 7, 9]
    ArrayExt.slice(data, { start: 0, stop: 4 }); // [0, 3, 4, 7]
    ArrayExt.slice(data, { step: 2 }); // [0, 4, 7]
    ArrayExt.slice(data, { step: -1 }); // [9, 7, 7, 4, 3, 0]