Lodash Internal baseIndexOf Function (Legacy)
The `lodash._baseindexof` package provides a standalone CommonJS module for Lodash's internal `baseIndexOf` utility, primarily intended for use within the Lodash v3 ecosystem. This function performs a basic index search within arrays. While it served a purpose in older modular builds of Lodash (stable at v3.1.0 for this package), modern Lodash (currently at v4.18.1 for the main `lodash` package, which has an active, regular release cadence) has transitioned away from these deeply internal, single-function packages. Developers are now encouraged to use direct imports from `lodash` (e.g., `import { indexOf } from 'lodash'`) or `lodash-es` for better tree-shaking and ESM compatibility. This specific package is no longer actively maintained or updated, making it functionally deprecated.
Common errors
-
TypeError: baseIndexOf is not a function
cause Attempting to use `baseIndexOf` after an incorrect or failed import, or if the module itself wasn't resolved correctly.fixVerify the `require('lodash._baseindexof')` statement is correct and that the package is installed. Ensure you're in a CommonJS environment or that your bundler correctly handles CJS imports for this legacy package. -
Error: Cannot find module 'lodash._baseindexof'
cause The package is not installed, or your environment is trying to resolve it as an ESM module without CJS fallback.fixRun `npm install lodash._baseindexof` or ensure your bundler (like Webpack) is configured with aliases or fallbacks if you're trying to use a different Lodash import path. Consider migrating to modern Lodash imports.
Warnings
- deprecated This package (`lodash._baseindexof` v3.1.0) is a legacy internal module from Lodash v3.x and is no longer actively maintained. Using it in modern applications is discouraged.
- breaking Lodash v4 introduced significant breaking changes compared to v3, including changes in modularization strategy. This package is not compatible with the standard Lodash v4 modular imports.
- gotcha This package is a CommonJS module (`require`). Direct `import` statements (ESM) will not work without proper bundler configuration for CJS interoperability.
Install
-
npm install lodash._baseindexof -
yarn add lodash._baseindexof -
pnpm add lodash._baseindexof
Imports
- baseIndexOf
const baseIndexOf = require('lodash._baseindexof'); - indexOf
import baseIndexOf from 'lodash._baseindexof';
import { indexOf } from 'lodash'; - indexOf
require('lodash/indexOf')import indexOf from 'lodash/indexOf';
Quickstart
const baseIndexOf = require('lodash._baseindexof');
// Example usage of baseIndexOf, which is similar to Array.prototype.indexOf
const numbers = [10, 20, 30, 40, 20];
console.log('Finding 30:', baseIndexOf(numbers, 30, 0)); // Expected: 2
console.log('Finding 20 from index 2:', baseIndexOf(numbers, 20, 2)); // Expected: 4
console.log('Finding 50 (not found):', baseIndexOf(numbers, 50, 0)); // Expected: -1
const objects = [{ id: 1 }, { id: 2 }, { id: 1 }];
// Note: baseIndexOf performs strict equality (===), so it won't work for objects directly.
console.log('Finding {id:1} (object equality):', baseIndexOf(objects, { id: 1 }, 0)); // Expected: -1
console.log('This module is part of Lodash v3 and uses CommonJS `require`.');
console.log('For modern applications, consider `import { indexOf } from "lodash"` or `lodash-es`.');