UNPKG

es-toolkit

Version:

A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.

27 lines (22 loc) 715 B
'use strict'; Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const isArrayLike = require('../predicate/isArrayLike.js'); function indexOf(array, searchElement, fromIndex) { if (!isArrayLike.isArrayLike(array)) { return -1; } if (Number.isNaN(searchElement)) { fromIndex = fromIndex ?? 0; if (fromIndex < 0) { fromIndex = Math.max(0, array.length + fromIndex); } for (let i = fromIndex; i < array.length; i++) { if (Number.isNaN(array[i])) { return i; } } return -1; } return Array.from(array).indexOf(searchElement, fromIndex); } exports.indexOf = indexOf;