Lodash _.omitBy() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.
The _.omitBy() method is used to return a copy of the object that composed of the own and inherited enumerable string keyed properties of the object that predicate doesn’t return truthy for. It is the opposite of _.pickBy() method.
Syntax:
_.omitBy( object, predicate )
Parameters: This method accepts two parameters as mentioned above and described below:
- 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:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // The source object var obj = { Name: "GeeksforGeeks" , password: 123456, username: "your_geeks" } // Using the _.omitBy() method console.log(_.omitBy(obj, _.isLength)); |
Output:
{Name: "GeeksforGeeks", username: "your_geeks"}
Example 2:
Javascript
// Requiring the lodash library const _ = require( "lodash" ); // The source object var obj = { 'x' : 1, 'y' : '2' , 'z' : 3 }; // Using the _.omitBy() method console.log(_.omitBy(obj, _.isNumber)); |
Output:
{'y': '2'}
Please Login to comment...