Skip to content

nth

js
_.nth(array, [n=0])

获取 array 中索引 n 处的元素。如果 n 为负数,则返回倒数第 n 个元素。

¥Gets the element at index n of array. If n is negative, the nth element from the end is returned.

新增于

¥Since

4.11.0

参数

¥Arguments

  1. array (数组):要查询的数组。

    ¥array (Array): The array to query.

  2. [n=0] (数值):要返回的元素的索引。

    ¥[n=0] (number): The index of the element to return.

返回

¥Returns

(*):返回 array 的第 n 个元素。

¥()*: Returns the nth element of array.

示例

¥Example

js
var array = ['a', 'b', 'c', 'd'];

_.nth(array, 1);
// => 'b'

_.nth(array, -2);
// => 'c';

Lodash v4.17 中文网 - 粤ICP备13048890号