Underscore.js _.pick() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Return a copy of the object, filtered to only have values for the whitelisted keys (or an array of valid keys). Alternatively accepts a predicate indicating which keys to pick (official Underscore docs). Stable helper — not deprecated. Does not mutate the source.

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

Syntax

Call _.pick. Start with this line.

Underscore
_.pick(object, *keys) or predicate Returns New object with only whitelisted keys Official example _.pick({name, age, userid}, "name", "age")
CallWhat it does
_.pick(object, *keys) or predicate Returns New object with only whitelisted keys Official example _.pick({name, age, userid}, "name", "age")Primary signature.
_.pick(...)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
_.pick(object, *keys) or predicate Returns New object with only whitelisted keys Official example _.pick({name, age, userid}, "name", "age")

Parameters

ParameterDescription
objectRequired. Source to copy from
*keys / arrayOptional. Property names to whitelist
predicateOptional. (value, key, object) → true means keep

Return Value

Return ValueDescription
*New object with only picked keys

Underscore.js Examples

Example 1 — Official: Keep name and age

The docs whitelist two keys and drop everything else.

Underscore
_.pick({name: "moe", age: 50, userid: "moe1"}, "name", "age");
// → {name: "moe", age: 50}
Try It Yourself

How It Works

  1. Source. Three own properties: name, age, userid.
  2. Whitelist. Only "name" and "age" are listed to keep.
  3. Copy. Underscore builds a new object with those keys.
  4. Official result. {name: "moe", age: 50}.

Example 2 — Array of Keys

Pass one array of names instead of separate arguments.

Underscore
var moe = {name: "moe", age: 50, userid: "moe1"};

_.pick(moe, ["name", "age"]);
// → {name: "moe", age: 50}

_.pick(moe, "name", "age");
// → {name: "moe", age: 50}   // same idea
Try It Yourself

How It Works

  1. Array form. Pass one array of key names.
  2. Varargs. Or list keys as separate string arguments.
  3. Same result. Both keep name and age.
  4. Safe. moe itself is not modified.

Example 3 — Predicate: Keep Numbers

Official style: pick properties where the value is a number.

Underscore
_.pick({name: "moe", age: 50, userid: "moe1"}, function (value, key, object) {
  return _.isNumber(value);
});
// → {age: 50}
Try It Yourself

How It Works

  1. Predicate. Called as (value, key, object) for each own key.
  2. True means keep. age: 50 is a number → kept.
  3. Drop strings. name and userid are omitted.
  4. Official pattern. Same idea as the docs predicate example.

Example 4 — _.pick vs _.omit

Whitelist versus blacklist on the same object.

Underscore
var moe = {name: "moe", age: 50, userid: "moe1"};

_.pick(moe, "name", "age");
// → {name: "moe", age: 50}

_.omit(moe, "userid");
// → {name: "moe", age: 50}   // same result, opposite approach
Try It Yourself

How It Works

  1. pick. Name what to keep — see this page.
  2. omit. Name what to remove — see _.omit.
  3. Same outcome. Here both leave name and age.
  4. Choose. Prefer pick when the keep list is shorter; omit when the drop list is shorter.

Browser & Runtime Support

_.pick 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. Handy for arrays of keys and predicates when object rest is not enough.

✓ Stable · Underscore 1.x

_.pick()

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
_.pick Underscore 1.x+

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

Frequently Asked Questions

_.pick(object, *keys) returns a copy of the object with only the whitelisted keys. Official example: _.pick({name: 'moe', age: 50, userid: 'moe1'}, 'name', 'age') returns {name: 'moe', age: 50}.
No. It returns a new object. The source is left untouched.
They are opposites. _.pick keeps only the keys you name (whitelist). _.omit removes the keys you name (blacklist).
Yes. A predicate (value, key, object) keeps every property for which it returns true — useful to pick by type or pattern.
Missing keys are ignored. They do not appear in the result and no error is thrown.
No. It is a stable Underscore object helper. Load Underscore 1.x and call _.pick(object, *keys).

Next: _.omit()

Drop blacklisted keys instead — the opposite of pick.

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