主题
take
js
_.take(array, [n=1])创建 array 的一个切片,其中从开头获取了 n 个元素。
¥Creates a slice of array with n elements taken from the beginning.
新增于
¥Since
0.1.0
参数
¥Arguments
array(数组):要查询的数组。¥
array(Array): The array to query.[n=1](数值):要获取的元素数。¥
[n=1](number): The number of elements to take.
返回
¥Returns
(数组):返回 array 的切片。
¥(Array): Returns the slice of array.
示例
¥Example
js
_.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);
// => []