Lodash _.pickBy() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Build a new object by keeping properties where a predicate returns truthy. Part of Lodash Object (stable — not deprecated). The predicate is invoked as (value, key). Opposite of _.omitBy.

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

Syntax

Call _.pickBy. Start with this line.

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

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

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

Parameters

ParameterDescription
objectRequired. Source object to filter
predicateOptional. Invoked as (value, key); default _.identity

Return Value

Return ValueDescription
*New object with matching properties

Lodash Examples

Example 1 — Official: Keep Numbers

Keep every property whose value is a number.

Lodash
var object = { a: 1, b: "2", c: 3 };

_.pickBy(object, _.isNumber);
// → { a: 1, c: 3 }
Try It Yourself

How It Works

  1. Predicate. _.isNumber checks each value.
  2. Keep. 1 and 3 are numbers → kept.
  3. Drop. "2" is a string → dropped.
  4. Docs. Matches the official Lodash example.

Example 2 — Default Predicate (Truthy Values)

With no predicate, identity keeps only truthy values.

Lodash
var flags = {
  dark: true,
  beta: false,
  count: 0,
  label: "on"
};

_.pickBy(flags);
// → { dark: true, label: "on" }
Try It Yourself

How It Works

  1. Default. Missing predicate → _.identity.
  2. Keep. Truthy true and "on" stay.
  3. Drop. false and 0 are falsy → removed.
  4. Caution. Prefer an explicit predicate if 0 / false matter.

Example 3 — Keep by Key Name

Use the second predicate argument to filter keys.

Lodash
var settings = {
  enableDark: true,
  enableBeta: false,
  theme: "light",
  locale: "en"
};

_.pickBy(settings, function (value, key) {
  return key.indexOf("enable") === 0;
});
// → { enableDark: true, enableBeta: false }
Try It Yourself

How It Works

  1. Key. Predicate receives key as the second arg.
  2. Rule. Keys starting with enable return truthy → kept.
  3. Value. false is still kept — the rule was on the key.
  4. Tip. For a fixed list of names, _.pick is simpler.

Example 4 — pickBy vs omitBy

Same predicate, opposite results.

Lodash
var object = { a: 1, b: "2", c: 3 };

console.log(_.pickBy(object, _.isNumber));
// → { a: 1, c: 3 }

console.log(_.omitBy(object, _.isNumber));
// → { b: "2" }
Try It Yourself

How It Works

  1. pickBy. Truthy predicate → keep.
  2. omitBy. Truthy predicate → drop.
  3. Same test. _.isNumber on the same object.
  4. Pick. Choose the helper that matches “keep” vs “drop” intent.

Example 5 — pickBy vs pick

Predicate rules vs a fixed key list.

Lodash
var user = { id: 1, name: "Sam", score: 42 };

_.pick(user, ["id", "name"]);
// → { id: 1, name: "Sam" }

_.pickBy(user, _.isNumber);
// → { id: 1, score: 42 }
Try It Yourself

How It Works

  1. pick. Best when keys are known literals.
  2. pickBy. Best when the rule depends on value or a pattern.
  3. Different results. Name vs number filter keep different fields.
  4. Choose. Prefer the shorter, clearer API for the job.

Browser & Runtime Support

_.pickBy is a Lodash Object helper available in 4.x. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native equivalents loop Object.keys and copy keys the predicate accepts.

✓ Stable · Lodash 4.x

_.pickBy()

Available in [email protected] full builds and the lodash/pickBy 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
_.pickBy Lodash 4.x

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import pickBy from "lodash/pickBy" for smaller builds. Use pick for fixed key lists; omitBy when you want to drop matches.

Frequently Asked Questions

_.pickBy(object, [predicate]) builds a new object from own enumerable string keys, keeping any property where the predicate returns a truthy value. Official example: _.pickBy({ a: 1, b: '2', c: 3 }, _.isNumber) → { a: 1, c: 3 }.
The predicate is invoked as predicate(value, key). Check the value for content rules, or the key for name-based rules.
No. It returns a new object and leaves the source unchanged.
_.pick() keeps a fixed list of paths/keys. _.pickBy() decides per property with a runtime predicate.
They are opposites. _.pickBy() keeps where the predicate is truthy; _.omitBy() drops where the predicate is truthy.
The default is _.identity, so only truthy values are kept. Prefer an explicit predicate when 0 or false must stay.

Next: _.result()

Resolve a nested path, invoking functions along the way.

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