Function slice

  • Negative indices count backwards from the end of the array. Like the built-in Array.slice(), the slice does not include the end index, and omitting both parameters returns a shallow copy of the array.

    Remarks

    Returns an empty array if start or end is fractional or NaN.

    Example

    import * as A from "flurp/array";

    const fromIndexTwo = A.slice(2);
    fromIndexTwo([0, 1, 2, 3, 4, 5, 6]); // [2, 3, 4, 5, 6]

    const lastTwo = A.slice(-2);
    lastTwo([0, 1, 2, 3, 4, 5, 6]); // [5, 6]

    const indexTwoAndThree = A.slice(2, 4);
    indexTwoAndThree([0, 1, 2, 3, 4, 5, 6]); // [2, 3]

    const shallowCopy = A.slice();
    shallowCopy([0, 1, 2, 3, 4, 5, 6]); // [0, 1, 2, 3, 4, 5, 6]

    Type Parameters

    • T

    Parameters

    • Optional startIndex: number
    • Optional endIndex: number

    Returns ((arr: readonly T[]) => T[])

      • (arr: readonly T[]): T[]
      • Parameters

        • arr: readonly T[]

        Returns T[]