|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
356 bytes
|
| Line | |
|---|
| 1 | import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
|
|---|
| 2 | import { toInteger } from '../util/toInteger.mjs';
|
|---|
| 3 |
|
|---|
| 4 | function nth(array, n = 0) {
|
|---|
| 5 | if (!isArrayLikeObject(array) || array.length === 0) {
|
|---|
| 6 | return undefined;
|
|---|
| 7 | }
|
|---|
| 8 | n = toInteger(n);
|
|---|
| 9 | if (n < 0) {
|
|---|
| 10 | n += array.length;
|
|---|
| 11 | }
|
|---|
| 12 | return array[n];
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | export { nth };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.