By the end of this tutorial, you’ll confidently strip unwanted properties from objects using Lodash’s _.omit() method.
01
Core Syntax
Call _.omit(object, paths) with string keys or an array of keys.
02
Non-Mutating
Get a new object back while the original stays untouched.
03
API Sanitization
Remove passwords, tokens, and internal fields before sending JSON.
04
Pair with _.defaults()
Omit unwanted keys, then fill missing values with fallbacks.
05
Pick vs Omit
Know when to exclude keys (_.omit) vs keep only some (_.pick).
06
Production Tips
Avoid shallow-copy pitfalls, dot-path confusion, and deny-list drift.
Fundamentals
What Is _.omit()?
_.omit() is a Lodash utility that builds a new object by copying every own enumerable string-keyed property from the source—except the keys you name in the second argument. It is the inverse of _.pick(): instead of choosing what to keep, you choose what to leave out.
💡
Beginner tip
Think of _.omit(user, ['password', 'token']) as “give me the user object, but without these sensitive fields.” The original user variable is not modified.
This pattern appears everywhere in real apps: trimming form state before submit, simplifying product cards for list views, and scrubbing database records before they reach the browser.
Foundation
📝 Syntax
The signature is simple—an object plus one or more property names to exclude:
javascript
_.omit(object, [paths])
Syntax Rules
object — the source object to copy from (not mutated).
paths — property names to exclude, passed as separate strings or a single array.
Return value — a new plain object without the omitted keys.
Shallow only — nested objects inside kept keys are shared by reference, not deep-cloned.
Top-level keys — _.omit(obj, 'a.b') looks for a literal key "a.b", not a nested path.
The source object. Lodash copies own enumerable string keys from this object. Passing null or undefined returns {}.
_.omit(user, ["email"])
pathsRequired
One or more property name strings to exclude. Pass them as separate arguments or wrap them in an array. Keys that do not exist are ignored safely.
_.omit(obj, "a", "b")
_.omit(obj, ["a", "b"])
return valueNew object
A plain object containing all copied properties except the omitted keys. The original object reference is unchanged.
const safe = _.omit(data, ["token"])
shallow copyImportant
Nested objects and arrays inside kept keys are not cloned. Changes to nested values in the result still affect the source unless you deep-clone separately.
// nested.address is shared
For nested field removal, transform the nested object first or use a dedicated utility—_.omit() alone cannot drill into child objects by dot notation.
Hands-On
Examples Gallery
Practical _.omit() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.
📚 Getting Started
Remove known keys from a plain object and verify the original stays intact.
Example 1 — Basic property exclusion
Strip email and profession from a user record before displaying a public profile.
Keep a fixed deny-list of sensitive field names in one place. When new secrets are added to the model, update the list—or consider an allow-list with _.pick() for public APIs.
Example 3 — Omit then fill defaults
Drop email from incoming data, then use _.defaults() to supply missing profile fields.
Use _.omit() when the key list is long, computed at runtime, or shared across modules. Destructuring is cleaner for two or three known keys in a single function.
Compare
📋 _.omit vs related operations
Topic
_.omit
_.pick
_.omitBy
Destructuring
Selection style
Exclude named keys
Keep named keys
Exclude by predicate
Exclude via rest ({ a, ...rest })
Mutates source
No
No
No
No
Depth
Top-level only
Top-level only
Top-level only
Top-level only
Dynamic keys
Fixed list
Fixed list
Condition-based
Fixed at write time
Best use
Known deny-list
Known allow-list
Value/key rules
Small objects, no Lodash
🧠 How _.omit() Works
1
Receive source object
Lodash reads own enumerable string keys from the object argument.
Input
2
Build omit set
All paths arguments are collected into a lookup set of keys to skip.
Filter
3
Shallow copy kept keys
Each non-omitted key is assigned to a fresh result object (references copied, not deep-cloned).
Copy
=
📦
New object returned
The source object is unchanged. You get a trimmed copy ready to send, display, or log.
Important
📝 Notes
_.omit() is non-mutating—always assign the result to a new variable.
Only top-level keys are removed; nested properties require a different approach.
Nested objects inside kept keys are shallow-copied (shared references).
Symbol-keyed and inherited properties are not included in the result.
Omitting a key that does not exist is safe—no error is thrown.
_.omit() is one of the most practical Lodash object helpers: name the keys you do not want, get a clean copy back, and leave the original data intact. Use it to sanitize API responses, trim form payloads, and simplify objects for display.
When removal rules depend on values rather than fixed key names, move on to _.omitBy(). For two or three keys in modern JavaScript, native rest destructuring may be enough.
Be explicit about which keys you exclude—keep deny-lists in one module
Assign the result to a new variable; never expect in-place mutation
Use _.omit() for fixed top-level key lists
Pair with _.defaults() when omitted fields need fallbacks
Document stripped fields in API response helpers
❌ Don’t
Assume dot-path strings remove nested properties
Rely on deny-lists for security without reviewing new model fields
Use _.omit() when removal depends on runtime conditions
Forget that nested values are still shared references
Depend on property order in the returned object
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.omit()
Use these points whenever you need to strip properties from an object.
5
Core concepts
📦01
New object
Non-mutating. Original stays intact.
Basics
🔑02
Deny-list
Name keys to exclude.
Pattern
🔒03
Sanitize
Strip secrets from API data.
Security
📐04
Shallow
Top-level keys only.
Depth
🔄05
omitBy
Use for dynamic rules.
Next step
❓ Frequently Asked Questions
_.omit() creates and returns a new object containing all own enumerable string-keyed properties from the source object except the keys you list to omit.
No. Unlike _.merge(), _.omit() is non-mutating. The source object stays the same; you get a shallow copy without the omitted keys.
Pass keys as separate arguments (_.omit(obj, 'a', 'b')) or as one array (_.omit(obj, ['a', 'b'])). Both forms are equivalent.
No. _.omit() works on top-level keys only. To strip nested fields, omit the parent key, use _.omitBy() with a custom predicate, or map/transform the object first.
_.pick() keeps only the keys you name. _.omit() keeps everything except the keys you name. They are opposites for top-level properties.
Use _.omitBy() when removal depends on a condition (value is null, key starts with '_', etc.). Use _.omit() when you already know the exact key names to exclude.
Did you know?
_.omit returns a new object and leaves the original untouched. It only removes top-level own enumerable string keys—for conditional removal use _.omitBy(), and for the opposite operation see _.pick() in the official docs.