Lodash _.omitBy() Method
Last Updated :
20 Oct, 2023
Lodash _.omitBy() method is used to return a copy of the object composed of the own and inherited enumerable string keyed properties of the object that the predicate doesn’t return truthy for. It is the opposite of _.pickBy() method.
Syntax:
_.omitBy( object, [predicate] );
Parameters:
- object: This parameter holds the source object.
- predicate: This parameter holds the function that is invoked for every property. It is an optional value.
Return Value:
This method returns the new object.
Example 1: In this example, we are omitting those values which do not support the _.isLength() method and returning the rest of the element as an object.
Javascript
const _ = require( "lodash" );
let obj = {
Name: "GeeksforGeeks" ,
password: 123456,
username: "your_geeks"
}
console.log(_.omitBy(obj, _.isLength));
|
Output:
{Name: "GeeksforGeeks", username: "your_geeks"}
Example 2: In this example, we are omiting those values which do not support the _.isNumber() method and returning the rest of the element as an object.
Javascript
const _ = require( "lodash" );
let obj = { 'x' : 1, 'y' : '2' , 'z' : 3 };
console.log(_.omitBy(obj, _.isNumber));
|
Output:
{'y': '2'}
Share your thoughts in the comments
Please Login to comment...