Skip to content

Function: take() ​

ts
function take<T>(array, count): T[];

Returns the first N items from an array. 返回数组前 N 个元素。

Type Parameters ​

Type ParameterDescription
TThe type of array items / 数组元素类型

Parameters ​

ParameterTypeDescription
arrayreadonly T[]The source array / 源数组
countnumberThe 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

Released under the MIT License.