主题
takeRight
js
_.takeRight(array, [n=1])
创建 array
的一个切片,其中从结尾获取了 n
个元素。
¥Creates a slice of array
with n
elements taken from the end.
新增于
¥Since
3.0.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
_.takeRight([1, 2, 3]);
// => [3]
_.takeRight([1, 2, 3], 2);
// => [2, 3]
_.takeRight([1, 2, 3], 5);
// => [1, 2, 3]
_.takeRight([1, 2, 3], 0);
// => []