source: node_modules/es-toolkit/dist/compat/array/nth.js

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 476 bytes
Line 
1'use strict';
2
3Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
5const isArrayLikeObject = require('../predicate/isArrayLikeObject.js');
6const toInteger = require('../util/toInteger.js');
7
8function nth(array, n = 0) {
9 if (!isArrayLikeObject.isArrayLikeObject(array) || array.length === 0) {
10 return undefined;
11 }
12 n = toInteger.toInteger(n);
13 if (n < 0) {
14 n += array.length;
15 }
16 return array[n];
17}
18
19exports.nth = nth;
Note: See TracBrowser for help on using the repository browser.