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().
Fundamentals
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.
Foundation
📝 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.
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.
Important
📝 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.
Wrap Up
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().
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.pick()
Use these whenever you need a focused slice of an object.
5
Core concepts
📌01
Allow-list
Keep named keys only.
Basics
📦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.