source: node_modules/es-toolkit/dist/compat/array/indexOf.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: 607 bytes
Line 
1import { isArrayLike } from '../predicate/isArrayLike.mjs';
2
3function indexOf(array, searchElement, fromIndex) {
4 if (!isArrayLike(array)) {
5 return -1;
6 }
7 if (Number.isNaN(searchElement)) {
8 fromIndex = fromIndex ?? 0;
9 if (fromIndex < 0) {
10 fromIndex = Math.max(0, array.length + fromIndex);
11 }
12 for (let i = fromIndex; i < array.length; i++) {
13 if (Number.isNaN(array[i])) {
14 return i;
15 }
16 }
17 return -1;
18 }
19 return Array.from(array).indexOf(searchElement, fromIndex);
20}
21
22export { indexOf };
Note: See TracBrowser for help on using the repository browser.