Function: take()
ts
function take<T>(array, count): T[];Returns the first N items from an array. 返回数组前 N 个元素。
Type Parameters
| Type Parameter | Description |
|---|---|
T | The type of array items / 数组元素类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
array | readonly T[] | The source array / 源数组 |
count | number | The number of items to take / 要获取的数量 |
Returns
T[]
A new array containing the selected items / 选中元素组成的新数组
Example
ts
take([1, 2, 3, 4], 2)
// => [1, 2]Since
1.2.0