Open In App

Lodash _.omit() Method

Last Updated : 18 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.omit() method is used to return a copy of the object that is composed of the own and inherited enumerable property paths of the given object that are not omitted. It is the opposite of the _.pick() method.

Note: The _.omit() method is slower than the _.pick() method.

Syntax:

_.omit(object, [paths])

Parameters:

  • object (Object) parameter holds the source object.
  • paths (…(string|string[])) parameter holds the property paths to omit.

Return value:

This method returns the new object.

Example 1: In this example, we have omitted the ‘name’ and ‘username’ by using the _.omit() method by passing the path.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// The source object
let obj = {
    name: "GeeksforGeeks",
    password: "gfg@1234",
    username: "your_geeks"
}
 
// Using the _.omit() method
console.log(_.omit(obj, ['name', 'username']));


Output:

 {password: "gfg@1234"}

Example 2:   In this example, we have omitted the ‘x’ and ‘y’ by using the _.omit() method by passing the path.

Javascript




// Requiring the lodash library 
const _ = require("lodash");
 
// The source object
let obj = { 'x': 1, 'y': '2', 'z': 3 };
 
// Use the _.omit() method
console.log(_.omit(obj, ['x', 'y']));


Output:

{'z': 3}

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads