Lodash _.findKey() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Returns the first own enumerable string key whose value satisfies the predicate, or undefined if nothing matches. Since Lodash 1.1.0.

Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.

Syntax

Call _.findKey. Start with this line.

Lodash
_.findKey(object, [predicate=_.identity])
CallWhat it does
_.findKey(object, [predicate=_.identity])Primary signature.
_.findKey(object)Work with an object’s keys, values, or paths.

Prefer import findKey from "lodash/findKey" when you want a smaller bundle.

Library declarations
Lodash
_.findKey(object, [predicate=_.identity])

Parameters

ParameterDescription
objectRequired. Source object to scan
predicateOptional. Defaults to _.identity (first truthy value)

Return Value

Return ValueDescription
*Matching key string, or undefined

Lodash Examples

Example 1 — Official: Function Predicate

Return the first key whose value passes your test.

Lodash
var users = {
  barney:  { age: 36, active: true },
  fred:    { age: 40, active: false },
  pebbles: { age: 1,  active: true }
};

_.findKey(users, function (o) { return o.age < 40; });
// → "barney"
Try It Yourself

How It Works

  1. Scan starts at barney (insertion order).
  2. Predicate gets the value object first: { age: 36, … }.
  3. 36 < 40 is truthy → return "barney".
  4. Stop. Later keys are not visited.

Example 2 — Official: Object Matcher

Pass a plain object — Lodash treats it as a partial-deep matcher.

Lodash
_.findKey(users, { age: 1, active: true });
// → "pebbles"
Try It Yourself

How It Works

  1. Matcher requires both age: 1 and active: true.
  2. barney / fred fail the age check.
  3. pebbles matches both fields → return that key.
  4. Tip. Extra fields on the value are fine; missing required fields fail.

Example 3 — Official: Property Shorthands

Array form is matchesProperty; string form tests a truthy property.

Lodash
_.findKey(users, ["active", false]);
// → "fred"

_.findKey(users, "active");
// → "barney"
Try It Yourself

How It Works

  1. ["active", false] finds the first value with active === false.
  2. "active" finds the first value where active is truthy.
  3. barney is active → string shorthand returns early.
  4. Pick array form for equality; string form for truthiness.

Example 4 — vs _.findLastKey

Same predicate; opposite scan direction.

Lodash
_.findKey(users, function (o) { return o.active; });
// → "barney"

_.findLastKey(users, function (o) { return o.active; });
// → "pebbles"
Try It Yourself

How It Works

  1. findKey walks forward → first active user is barney.
  2. findLastKey walks backward → last active user is pebbles.
  3. fred is skipped in both cases (active: false).
  4. Pick based on whether you want the earliest or latest match.

Example 5 — No Match & Nested Matcher

Misses return undefined; nest matchers — don’t use dotted keys in the object form.

Lodash
_.findKey(users, { age: 99 });
// → undefined

var accounts = {
  jane: { details: { isAdmin: false } },
  root: { details: { isAdmin: true } }
};

_.findKey(accounts, { "details.isAdmin": true });
// → undefined   // literal key name, not a path

_.findKey(accounts, { details: { isAdmin: true } });
// → "root"

_.findKey(accounts, ["details.isAdmin", true]);
// → "root"
Try It Yourself

How It Works

  1. No match → always undefined; guard before use.
  2. Dotted key in a matcher object is a literal property name.
  3. Nested object or [path, value] walks the real path.
  4. Prefer nesting or the array shorthand for deep fields.

Browser & Runtime Support

_.findKey is a Lodash Object helper (since 1.1.0). It runs anywhere Lodash 4.x runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 1.1.0+

_.findKey()

Available in [email protected] full builds and the lodash/findKey modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.findKey Lodash 1.1.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import findKey from "lodash/findKey". Use findLastKey when you need the last match.

Frequently Asked Questions

The first own enumerable string key whose value satisfies the predicate, or undefined when nothing matches.
(value, key, object). Value comes first — same shape as _.find — not (key, value).
Function; string property (truthy test); [path, value] matchesProperty pair; and a plain object used as a partial-deep matcher.
No. Nest the object ({ details: { isAdmin: true } }) or use ['details.isAdmin', true] with the array shorthand.
_.find returns the matched value; _.findKey returns the matched key. Same predicate rules.
Same behavior, opposite direction: findLastKey returns the last matching key.

Next: _.findLastKey()

Return the last own key whose value matches a predicate.

_.findLastKey() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful