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

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 
1import { isArrayLikeObject } from '../predicate/isArrayLikeObject.mjs';
2import { toInteger } from '../util/toInteger.mjs';
3
4function 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
15export { nth };
Note: See TracBrowser for help on using the repository browser.