Lodash _.findLastKey() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Returns the last own enumerable string key whose value satisfies the predicate, or undefined if nothing matches. Same rules as _.findKey, reverse scan. Since Lodash 2.0.0.

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

Syntax

Call _.findLastKey. Start with this line.

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

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

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

Parameters

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

Return Value

Return ValueDescription
*Matching key string, or undefined

Lodash Examples

Example 1 — Official: Function Predicate

Return the last key whose value passes your test.

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

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

How It Works

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

Example 2 — Official: Object Matcher

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

Lodash
_.findLastKey(users, { age: 36, active: true });
// → "barney"
Try It Yourself

How It Works

  1. Matcher requires both age: 36 and active: true.
  2. Reverse scan: pebbles and fred fail.
  3. barney matches both fields → return that key.
  4. Tip. Only one entry matches here, so direction does not change the answer.

Example 3 — Official: Property Shorthands

Array form is matchesProperty; string form tests a truthy property from the end.

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

_.findLastKey(users, "active");
// → "pebbles"
Try It Yourself

How It Works

  1. ["active", false] finds the last value with active === false.
  2. "active" finds the last value where active is truthy.
  3. pebbles is the last active user → string shorthand returns it.
  4. Compare: _.findKey(users, "active") would return "barney".

Example 4 — vs _.findKey

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
_.findLastKey(users, { age: 99 });
// → undefined

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

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

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

_.findLastKey(accounts, ["details.isAdmin", true]);
// → "ops"
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 / array forms find the last admin → "ops".
  4. findKey with the same nested matcher would return "root".

Browser & Runtime Support

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

✓ Stable · Lodash 2.0.0+

_.findLastKey()

Available in [email protected] full builds and the lodash/findLastKey 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
_.findLastKey Lodash 2.0.0+

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

Frequently Asked Questions

The last own enumerable string key whose value satisfies the predicate, or undefined when nothing matches.
Same predicate rules and return type. findKey scans forward (first match); findLastKey scans in reverse (last match).
(value, key, object). Value comes first — same shape as _.findKey and _.find.
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.
Own enumerable string keys only. Inherited and symbol keys are skipped.

Next: _.forIn()

Iterate an object’s own and inherited enumerable string keys.

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