Lodash `_.findWhere` Legacy Module
The `lodash.findwhere` package provides the `_.findWhere` utility function, originally part of Lodash v3. This standalone module is frozen at version 3.1.0, reflecting the state of the function in the broader Lodash library prior to its major v4 release. `_.findWhere` was deprecated and subsequently removed in Lodash v4 in favor of `_.find` combined with an object shorthand predicate. Consequently, this module is no longer actively maintained or receiving updates, including security patches, that are applied to the modern `lodash` package. Its primary use case now is for maintaining compatibility with legacy codebases tied to Lodash v3, or for selectively importing this specific deprecated functionality into projects that are otherwise on newer Lodash versions but require this exact behavior. Its release cadence is effectively ceased.
Common errors
-
TypeError: _.findWhere is not a function
cause Attempting to use `_.findWhere` after upgrading the main `lodash` package to version 4 or higher, which removed the function.fixReplace `_.findWhere(collection, predicate)` with `_.find(collection, predicate)` from Lodash v4+ or install `lodash.findwhere` explicitly if you must use the legacy function. -
Cannot find module 'lodash.findwhere'
cause The `lodash.findwhere` dependency is not installed or the import path is incorrect, especially in projects not configured for legacy modules.fixInstall `lodash.findwhere` via `npm install lodash.findwhere` if you explicitly intend to use this deprecated module. Otherwise, consider refactoring to use `_.find` from the main `lodash` package.
Warnings
- breaking The `_.findWhere` function was completely removed from the main Lodash library in version 4. This `lodash.findwhere` package provides the v3 implementation and is incompatible with modern Lodash's API for this functionality. Direct use of `_.findWhere` will result in a `TypeError: _.findWhere is not a function` if relying on a v4+ `lodash` bundle.
- deprecated This `lodash.findwhere` package is effectively abandoned. It is frozen at v3.1.0 and will not receive security updates, bug fixes, or enhancements applicable to modern `lodash` versions (v4 and beyond). Continuing to use it may expose projects to unpatched vulnerabilities.
- gotcha Mixing `lodash.findwhere` (from Lodash v3) with a modern `lodash` (v4+) bundle can lead to unexpected behavior, increased bundle sizes due to duplicate functionality, and potential conflicts. The functionality provided by this module is superseded by a different API.
Install
-
npm install lodash.findwhere -
yarn add lodash.findwhere -
pnpm add lodash.findwhere
Imports
- findWhere
const findWhere = require('lodash.findwhere');
Quickstart
const findWhere = require('lodash.findwhere');
const users = [
{ 'user': 'barney', 'age': 36, 'active': true },
{ 'user': 'fred', 'age': 40, 'active': false },
{ 'user': 'pebbles', 'age': 1, 'active': true }
];
// Find an object where 'age' is 1 and 'active' is true
const result = findWhere(users, { 'age': 1, 'active': true });
console.log(result); // => { 'user': 'pebbles', 'age': 1, 'active': true }
// This demonstrates the original behavior of _.findWhere, which has been superseded.