Function slice

  • Creates a slice of array from start up to, but not including, end.

    Note: This method is used instead of Array#slice to ensure dense arrays are returned.

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array to slice.

    • Optional start: number

      The start position. A negative index will be treated as an offset from the end.

      Optional
    • Optional end: number

      The end position. A negative index will be treated as an offset from the end.

      Optional

    Returns T[]

    Returns the slice of array.

    Since

    5.6.0

    Example

    var array = [1, 2, 3, 4]

    slice(array, 2)
    // => [3, 4]