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

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.

📝 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.
javascript
import omit from "lodash/omit";

const user = {
  name: "John",
  age: 30,
  email: "john@example.com",
  profession: "Developer"
};

const publicProfile = omit(user, ["email", "profession"]);
// -> { name: "John", age: 30 }

⚡ Quick Reference

TaskCode patternResult
Omit array of keys_.omit(obj, ["a", "b"])New object without a and b
Omit variadic keys_.omit(obj, "a", "b")Same as array form
Sanitize response_.omit(record, ["password"])Safe payload for client
Omit then default_.defaults(_.omit(obj, ["x"]), { y: 1 })Fill missing fields
Native alternativeconst { secret, ...rest } = objES2018 rest destructuring
Conditional omit_.omitBy(obj, predicate)Use when rules are dynamic
Mutates?
No

Returns a new object

Depth
Shallow

Top-level keys only

Opposite
_.pick()

Keep named keys

Dynamic
_.omitBy()

Predicate-based

🧰 Parameters

Every argument to _.omit() and what it controls:

object Required

The source object. Lodash copies own enumerable string keys from this object. Passing null or undefined returns {}.

_.omit(user, ["email"])
paths Required

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 value New object

A plain object containing all copied properties except the omitted keys. The original object reference is unchanged.

const safe = _.omit(data, ["token"])
shallow copy Important

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.

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.

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

const publicProfile = _.omit(user, ["email", "profession"]);

console.log(publicProfile);
// -> { name: "John", age: 30 }

console.log(user.email);
// still "john@example.com"
Try It Yourself

How It Works

_.omit() copies every enumerable key except those listed. Because it returns a new object, user.email is still available on the original.

📈 Practical Patterns

Sanitize API payloads, combine with defaults, and simplify real-world data structures.

Example 2 — Sanitize sensitive data

Remove password and role from a database user before serializing a JSON response.

javascript
const dbUser = {
  id: 42,
  username: "john_doe",
  password: "hashed-secret-value",
  email: "john@example.com",
  role: "admin"
};

const safePayload = _.omit(dbUser, ["password", "role"]);

console.log(safePayload);
// -> { id: 42, username: "john_doe", email: "john@example.com" }
Try It Yourself

How It Works

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.

javascript
const incoming = {
  name: "Bob",
  age: 30,
  email: "bob@example.com"
};

const profile = _.defaults(
  _.omit(incoming, ["email"]),
  { profession: "Unknown", country: "N/A" }
);

console.log(profile);
// -> { name: "Bob", age: 30, profession: "Unknown", country: "N/A" }
Try It Yourself

How It Works

_.defaults() only fills properties that are undefined on the first argument. Omit first so unwanted keys never appear in the final object.

Example 4 — Simplify a product for list view

Drop verbose fields like description and createdAt when rendering a compact product card.

javascript
const product = {
  id: 1,
  name: "Wireless Mouse",
  description: "Long marketing copy…",
  category: "Electronics",
  price: 29.99,
  createdAt: "2024-02-24T12:00:00Z"
};

const listItem = _.omit(product, ["description", "createdAt"]);
// -> { id: 1, name: "Wireless Mouse", category: "Electronics", price: 29.99 }

Example 5 — Filter user preferences

Show only the settings relevant to a theme toggle panel by omitting font and notification keys.

javascript
const prefs = {
  darkMode: true,
  fontSize: "medium",
  language: "en",
  showNotifications: true
};

const displayPrefs = _.omit(prefs, ["fontSize", "showNotifications"]);
// -> { darkMode: true, language: "en" }

🚀 Beyond the Basics

Modern JavaScript alternatives and when to reach for related Lodash helpers.

Example 6 — Native destructuring alternative

For a small, fixed set of keys, ES2018 rest destructuring can replace _.omit() without a library.

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

const { email, isAdmin, ...publicUser } = user;
// publicUser -> { name: "Alice", age: 25 }

// Lodash equivalent:
const same = _.omit(user, ["email", "isAdmin"]);

When to prefer Lodash

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.

🧠 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.

📝 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.
  • For conditional removal, use _.omitBy() instead.

Conclusion

_.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.

💡 Best Practices

✅ Do

  • 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

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
🔑 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.

Practice _.omit() in the Live Editor

Open the Try It editor, run the examples, and experiment with your own key 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