Function take

  • Creates a slice of array with n elements taken from the beginning.

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array to query.

    • Optional n: number

      The number of elements to take.

      Optional
    • Optional guard: any
      Optional

    Returns T[]

    Returns the slice of array.

    Since

    5.6.0

    Example

    take([1, 2, 3])
    // => [1]

    take([1, 2, 3], 2)
    // => [1, 2]

    take([1, 2, 3], 5)
    // => [1, 2, 3]

    take([1, 2, 3], 0)
    // => []