main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
669 bytes
|
Line | |
---|
1 | import baseNth from './_baseNth.js';
|
---|
2 | import toInteger from './toInteger.js';
|
---|
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 | export default nth;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.