@nevware21/ts-utils
    Preparing search index...

    Function arrTake

    • The arrTake() method returns a new array with the first n elements from the source array. If n is greater than the array length, returns all elements. If n is negative or 0, returns empty array.

      Type Parameters

      • T

        Identifies the base type of array elements

      Parameters

      • theArray: ArrayLike<T>

        The array or array-like object to take from

      • count: number

        The number of elements to take from the beginning

      Returns T[]

      A new array containing the first n elements

      0.14.0

      arrTake([1, 2, 3, 4, 5], 3);    // [1, 2, 3]
      arrTake(["a", "b", "c"], 2); // ["a", "b"]
      arrTake([1, 2], 5); // [1, 2]
      arrTake([1, 2, 3], 0); // []
      arrTake([1, 2, 3], -1); // []

      // Array-like objects
      arrTake({ length: 4, 0: 1, 1: 2, 2: 3, 3: 4 }, 2); // [1, 2]