Lodash _.pick() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Object utilities

What You’ll Learn

By the end of this tutorial, you’ll use _.pick() to extract only the properties you need from JavaScript objects.

01

Core Syntax

Call _.pick(object, paths) with string keys or an array.

02

Allow-list

Name what to keep—everything else is excluded.

03

Non-Mutating

Get a new object; the source stays unchanged.

04

API responses

Send only public fields to clients with a fixed key list.

05

pick vs omit

Choose allow-lists vs deny-lists for object shaping.

06

Production tips

Handle missing keys, shallow copies, and when to use _.pickBy().

What Is _.pick()?

_.pick() is Lodash’s allow-list helper. You pass an object and the property names you want; Lodash returns a new object containing only those keys. It is the mirror image of _.omit(), which removes named keys instead of keeping them.

💡
Beginner tip

Think of _.pick(user, ['id', 'name', 'email']) as “give me just these three fields.” Passwords, tokens, and internal flags never appear in the result because they were not on the list.

Use _.pick() when you know exactly which fields belong in a DTO, table row, or API payload—especially when an allow-list is safer than trying to remember every secret field to omit.

📝 Syntax

The signature mirrors _.omit()—only the selection logic is inverted:

javascript
_.pick(object, [paths])

Syntax Rules

  • object — the source object to copy from (not mutated).
  • paths — one or more property names to include (strings or an array of strings).
  • Return value — a new plain object with only the picked keys that exist on the source.
  • Missing keys — if a named key is absent, it is skipped silently (no error).
  • Shallow only — top-level keys; nested paths like address.city are not supported.
javascript
import pick from "lodash/pick";

const user = {
  name: "John Doe",
  age: 30,
  email: "john@example.com",
  isAdmin: true
};

const contact = pick(user, ["name", "email"]);
// -> { name: "John Doe", email: "john@example.com" }

⚡ Quick Reference

TaskCode patternResult
Pick array of keys_.pick(obj, ["a", "b"])New object with only a and b
Pick variadic keys_.pick(obj, "a", "b")Same as array form
Public API fields_.pick(user, ["id", "name", "email"])Safe allow-list response
Missing key_.pick({ a: 1 }, ["a", "b"]){ a: 1 } — no error
Exclude named keys_.omit(obj, ["secret"])Use _.omit() instead
Conditional pick_.pickBy(obj, predicate)Use when rules are dynamic
Mutates?
No

Returns a new object

Depth
Shallow

Top-level keys only

Opposite
_.omit()

Exclude named keys

Dynamic
_.pickBy()

Predicate-based

🧰 Parameters

Arguments to _.pick() and what they control:

object Required

The source object. Lodash copies only the named keys that exist as own enumerable string properties. null and undefined return {}.

_.pick(record, ["id", "title"])
paths Required

One or more property name strings to include. Pass individually or as an array. Keys not on the source are ignored.

_.pick(obj, "a", "b")
_.pick(obj, ["a", "b"])
return value New object

A plain object with only the picked properties. The original object is never modified.

const slim = _.pick(data, fields)
shallow copy Important

Nested objects and arrays inside picked keys are copied by reference, not deep-cloned.

// nested values are shared

For nested field selection, pick the parent key or transform nested data separately—_.pick() does not accept dot-path strings like profile.name.

Examples Gallery

Practical _.pick() patterns with sample output and interactive Try It Yourself labs.

📚 Getting Started

Extract a small set of known properties from a plain object.

Example 1 — Pick contact fields

Keep only name and email from a user record for a contact card.

javascript
const user = {
  name: "John Doe",
  age: 30,
  email: "john@example.com",
  isAdmin: true
};

const contact = _.pick(user, ["name", "email"]);

console.log(contact);
// -> { name: "John Doe", email: "john@example.com" }

console.log(user.isAdmin);
// still true — original unchanged
Try It Yourself

How It Works

Only keys listed in the second argument are copied. age and isAdmin are left out because they were not picked.

Example 2 — Missing keys are ignored

Picking a key that does not exist is safe—Lodash simply omits it from the result.

javascript
const user = {
  name: "Bob",
  age: 30
};

const partial = _.pick(user, ["name", "email"]);

console.log(partial);
// -> { name: "Bob" }
Try It Yourself

How It Works

No exception is thrown for email. This makes _.pick() useful when optional fields may or may not be present on the source.

📈 Practical Patterns

Shape API payloads, transform responses, and extract form fields for submission.

Example 3 — Public API allow-list

Return only safe user fields from an Express route—a fixed allow-list beats hoping you remembered every secret key.

javascript
const PUBLIC_USER_FIELDS = ["id", "name", "email"];

app.get("/user/:id", (req, res) => {
  const user = fetchUserFromDb(req.params.id);
  res.json(_.pick(user, PUBLIC_USER_FIELDS));
});
Try It Yourself

How It Works

Even if the database row contains password or isAdmin, they never reach the client because they are not on the allow-list.

Example 4 — Transform nested API data

Pick fields from a nested data object when normalizing an API response.

javascript
const rawApiResponse = {
  status: "success",
  data: {
    id: "456",
    name: "Jane Doe",
    email: "jane@example.com",
    internalToken: "secret"
  }
};

const transformed = {
  status: rawApiResponse.status,
  user: _.pick(rawApiResponse.data, ["id", "name", "email"])
};

// -> {
//      status: "success",
//      user: { id: "456", name: "Jane Doe", email: "jane@example.com" }
//    }

Example 5 — Extract form fields for submit

Pick only the fields your backend expects from a larger client-side form state object.

javascript
const formState = {
  title: "My post",
  body: "Hello world",
  isDirty: true,
  errors: {},
  lastSavedAt: "2026-07-06T09:00:00Z"
};

const payload = _.pick(formState, ["title", "body"]);
// -> { title: "My post", body: "Hello world" }

🚀 Beyond the Basics

Native alternatives and when predicate-based _.pickBy() fits better.

Example 6 — Explicit destructuring alternative

For a few known keys, object destructuring can replace _.pick() without Lodash.

javascript
const user = {
  name: "Alice",
  age: 25,
  email: "alice@example.com",
  isAdmin: false
};

const { name, email } = user;
const contact = { name, email };
// same as _.pick(user, ["name", "email"])

When to prefer Lodash

Use _.pick() when the key list is stored in a constant, computed at runtime, or reused across modules—especially for API field allow-lists.

🧠 How _.pick() Works

1

Receive source object

Lodash reads the object and builds a set of requested key names.

Input
2

Match own keys

For each requested name, if the source has that own enumerable string key, it qualifies for copy.

Match
3

Shallow copy matches

Matched values are assigned to a fresh result object (references copied, not deep-cloned).

Copy
=

Slim object returned

Only allow-listed keys appear. Source object unchanged and ready for reuse.

📝 Notes

  • _.pick() is non-mutating—assign the result to a new variable.
  • Only top-level keys are selected; nested paths require separate handling.
  • Nested values inside picked keys are shallow-copied (shared references).
  • Missing keys in the pick list produce no error and no property in the result.
  • Symbol-keyed and inherited properties are not picked by name.
  • For conditional selection, use _.pickBy() instead.

Conclusion

_.pick() is the straightforward way to build allow-list objects in Lodash: name the keys you need, get a focused copy back, and leave the source untouched. It is especially valuable for API responses, DTOs, and trimming fat objects down to essentials.

When you need to exclude known keys instead, use _.omit(). When selection depends on runtime rules, move on to _.pickBy().

💡 Best Practices

✅ Do

  • Store public API field lists in named constants
  • Prefer allow-lists (_.pick) for security-sensitive responses
  • Assign the result to a new variable; keep the source intact
  • Reuse the same key array across serializers and tests
  • Use _.pick() when the key set is fixed and small

❌ Don’t

  • Assume dot-path strings select nested properties
  • Expect picked keys that do not exist to appear as undefined
  • Use _.pick() when predicate rules would be clearer
  • Forget that nested objects are shared by reference
  • Hard-code long key lists inline in many files—centralize them

Key Takeaways

Knowledge Unlocked

Five things to remember about _.pick()

Use these whenever you need a focused slice of an object.

5
Core concepts
📦 02

New object

Non-mutating copy.

Pattern
🔒 03

API safety

Public field lists.

Security
📐 04

Shallow

Top-level keys only.

Depth
🔀 05

vs omit

Inverse of deny-list.

Compare

❓ Frequently Asked Questions

_.pick() creates and returns a new object containing only the own enumerable string-keyed properties you name. Every other key on the source object is left out.
No. _.pick() is non-mutating. The source object stays the same; you get a shallow copy with only the picked keys.
Pass keys as separate arguments (_.pick(obj, 'a', 'b')) or as one array (_.pick(obj, ['a', 'b'])). Both forms are equivalent.
Lodash silently skips it. The result simply will not include that key—no error is thrown.
_.pick() is an allow-list: you name what to keep. _.omit() is a deny-list: you name what to remove. They are opposites for top-level properties.
Use _.pickBy() when selection depends on a condition (value is a number, key ends with Id, etc.). Use _.pick() when you already know the exact key names to include.
Did you know?

_.pick and _.omit are exact opposites for top-level keys: picking ["a","b"] on an object with keys a, b, c gives the same result as omitting ["c"]. For public APIs, allow-lists with _.pick are often safer because new sensitive fields are excluded by default.

Practice _.pick() in the Live Editor

Open the Try It editor, run the examples, and experiment with your own allow-lists.

Open Try It editor →

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.

6 people found this page helpful