Last change
on this file since e29cc2e was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
671 bytes
|
Line | |
---|
1 | var baseNth = require('./_baseNth'),
|
---|
2 | toInteger = require('./toInteger');
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * Gets the element at index `n` of `array`. If `n` is negative, the nth
|
---|
6 | * element from the end is returned.
|
---|
7 | *
|
---|
8 | * @static
|
---|
9 | * @memberOf _
|
---|
10 | * @since 4.11.0
|
---|
11 | * @category Array
|
---|
12 | * @param {Array} array The array to query.
|
---|
13 | * @param {number} [n=0] The index of the element to return.
|
---|
14 | * @returns {*} Returns the nth element of `array`.
|
---|
15 | * @example
|
---|
16 | *
|
---|
17 | * var array = ['a', 'b', 'c', 'd'];
|
---|
18 | *
|
---|
19 | * _.nth(array, 1);
|
---|
20 | * // => 'b'
|
---|
21 | *
|
---|
22 | * _.nth(array, -2);
|
---|
23 | * // => 'c';
|
---|
24 | */
|
---|
25 | function nth(array, n) {
|
---|
26 | return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
|
---|
27 | }
|
---|
28 |
|
---|
29 | module.exports = nth;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.