The lodash method _.indexOf exported as a module.
npx @tessl/cli install tessl/npm-lodash--indexof@4.0.0The lodash.indexof package provides the lodash _.indexOf method as a standalone Node.js module, enabling efficient array searching functionality with SameValueZero equality comparisons.
npm install lodash.indexof (recommended: npm i -g npm first to update npm)const indexOf = require('lodash.indexof');For ES modules (with compatible bundlers):
import indexOf from 'lodash.indexof';const indexOf = require('lodash.indexof');
// Basic search
indexOf([1, 2, 1, 2], 2);
// => 1
// Search from specific index
indexOf([1, 2, 1, 2], 2, 2);
// => 3
// Value not found
indexOf([1, 2, 3], 4);
// => -1
// Handle NaN values correctly
indexOf([1, NaN, 3], NaN);
// => 1Gets the index at which the first occurrence of a value is found in an array using SameValueZero equality comparisons. If fromIndex is negative, it's used as the offset from the end of array.
/**
* Gets the index at which the first occurrence of `value` is found in `array`
* using SameValueZero for equality comparisons. If `fromIndex` is negative,
* it's used as the offset from the end of `array`.
*
* @param {Array} array - The array to inspect
* @param {*} value - The value to search for
* @param {number} [fromIndex=0] - The index to search from
* @returns {number} Returns the index of the matched value, else -1
*/
function indexOf(array, value, fromIndex);Parameters:
array (Array): The array to inspectvalue (*): The value to search forfromIndex (number, optional): The index to search from (default: 0)Returns:
Usage Examples:
const indexOf = require('lodash.indexof');
// Basic usage
indexOf([1, 2, 1, 2], 2);
// => 1
// Search from specific index
indexOf([1, 2, 1, 2], 2, 2);
// => 3
// Negative fromIndex (offset from end)
indexOf([1, 2, 1, 2], 1, -2);
// => 2
// Handle special values
indexOf([1, NaN, 3], NaN); // Uses SameValueZero
// => 1
indexOf([1, undefined, 3], undefined);
// => 1
indexOf([1, null, 3], null);
// => 1
// Empty array
indexOf([], 1);
// => -1
// Value not found
indexOf([1, 2, 3], 'a');
// => -1The function uses SameValueZero equality comparison, which means:
===)The implementation includes optimizations for:
baseIsNaN function