Underscore.js _.findKey() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Similar to _.findIndex, but for objects — returns the key where the predicate truth test passes, or undefined (official Underscore docs).

Pass the required arguments shown below. Underscore object helpers usually return a new value — check whether the source object is mutated.

Syntax

Call _.findKey. Start with this line.

Underscore
_.findKey(object, predicate, [context])
CallWhat it does
_.findKey(object, predicate, [context])Primary signature.
_.findKey(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.findKey(object, predicate, [context])

Parameters

ParameterDescription
objectRequired. Object whose values are tested
predicateRequired. Function, property string, or matcher object
contextOptional. this for a function predicate

Return Value

Return ValueDescription
*Matching key string, or undefined

Underscore.js Examples

Example 1 — Function Predicate

Return the key of the first value that passes your test.

Underscore
var users = {
  ada: { age: 36, active: true },
  linus: { age: 55, active: false },
  grace: { age: 45, active: true }
};

_.findKey(users, function (u) {
  return u.age > 40;
});
// → "linus"
Try It Yourself

How It Works

  1. Walk. Values are tested in enumeration order.
  2. ada. Age 36 fails the > 40 test.
  3. linus. Age 55 passes — return key "linus".
  4. Stop. grace is never checked.

Example 2 — Matcher Object

Pass an object of properties that must all match.

Underscore
var users = {
  ada: { age: 36, active: true },
  linus: { age: 55, active: false },
  grace: { age: 45, active: true }
};

_.findKey(users, { active: true });
// → "ada"
Try It Yourself

How It Works

  1. Shorthand. { active: true } becomes a matcher predicate.
  2. First hit. ada is active → return "ada".
  3. Later matches. grace is also active but never reached.
  4. vs findWhere. Similar idea on collections; here the result is a key.

Example 3 — Property Shorthand

A string checks for a truthy property on each value.

Underscore
var flags = {
  draft: { published: false },
  live: { published: true },
  archived: { published: false }
};

_.findKey(flags, "published");
// → "live"
Try It Yourself

How It Works

  1. Shorthand. "published" means “is value.published truthy?”
  2. draft. false → skip.
  3. live. true → return "live".
  4. Custom? Need more logic → use a function predicate.

Example 4 — _.findKey vs _.find

Same predicate — key vs value.

Underscore
var users = {
  ada: { age: 36 },
  linus: { age: 55 }
};

_.findKey(users, function (u) {
  return u.age > 40;
});
// → "linus"

_.find(users, function (u) {
  return u.age > 40;
});
// → { age: 55 }
Try It Yourself

How It Works

  1. Shared test. Both look for age > 40.
  2. findKey. Hands back the property name "linus".
  3. find. Hands back the value object { age: 55 }.
  4. Pick by intent. Need the id/key → findKey; need the record → find.

Browser & Runtime Support

_.findKey ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.findKey()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.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 Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.findKey(object, predicate, [context]) returns the key of the first value for which the predicate is truthy. If nothing matches, it returns undefined.
_.find returns the matching value. _.findKey returns the matching key (property name). Both stop at the first success.
Each call gets (value, key, object). You can test the value, the key, or both.
undefined — same idea as _.find when no element passes.
Yes. A property name string or a matcher object works — Underscore builds the predicate via _.property or _.matcher.
No. It only reads properties and returns a key string (or undefined).

Next: _.extend()

Copy enumerable properties from sources into a destination object.

_.extend() 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.

10 people found this page helpful