mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-18 05:21:43 +03:00
cf65b2c601
* chore: add prettierrc * chore: apply format with prettier config * chore: eslint error fix
630 B
630 B
take
Returns a new array containing the first count
elements from the input array arr
.
If count
is greater than the length of arr
, the entire array is returned.
Signature
function take<T>(arr: T[], count: number): T[];
Parameters
arr
(T[]
): The array to take elements from.count
(number
): The number of elements to take.
Returns
(T[]
): A new array containing the first count
elements from arr
.
Examples
// Returns [1, 2, 3]
take([1, 2, 3, 4, 5], 3);
// Returns ['a', 'b']
take(['a', 'b', 'c'], 2);
// Returns [1, 2, 3]
take([1, 2, 3], 5);