Lodash _.omit() Method
Last Updated :
18 Oct, 2023
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
const _ = require( "lodash" );
let obj = {
name: "GeeksforGeeks" ,
password: "gfg@1234" ,
username: "your_geeks"
}
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
const _ = require( "lodash" );
let obj = { 'x' : 1, 'y' : '2' , 'z' : 3 };
console.log(_.omit(obj, [ 'x' , 'y' ]));
|
Output:
{'z': 3}
Share your thoughts in the comments
Please Login to comment...