> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/array/nth.md).

# \_.nth（获取元素的值）

**语法：**

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

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L7671)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.nth)

**描述：**

获取`array`数组的第n个元素。如果`n`为负数，则返回从数组结尾开始的第n个元素。

**开始版本：**&#x34;.11.0

**参数：**

* `array (Array)`:要查询的数组。
* `[n=0] (number)`: 要返回元素的索引值。

**返回值：**

* `(*)`: 获取array数组的第n个元素。

**例子：**

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

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

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