The _.omit() function is used to return a copy of the object that filtered to omit the blacklisted keys.
Syntax:
_.omit(object, *keys)
Parameters: This function accept two parameters as mentioned above and described below:
- object: This parameter holds the value of an object.
- keys: It is an optional parameter. It contains the key name that value need to be omitted.
Return Value: It returns a copy of the object that filtered to omit the blacklisted keys.
Example 1:
<!DOCTYPE html> < html > Â Â < head > Â Â Â Â < script type = "text/javascript" src = Â Â Â Â </ script > </ head > Â Â < body > Â Â Â Â < script type = "text/javascript" > Â Â Â Â Â Â Â Â Â Â var info = { Â Â Â Â Â Â Â Â Â Â Â Â Company: 'neveropen', Â Â Â Â Â Â Â Â Â Â Â Â Address: 'Noida', Â Â Â Â Â Â Â Â Â Â Â Â Contact: '+91 9876543210' Â Â Â Â Â Â Â Â }; Â Â Â Â Â Â Â Â Â Â console.log(_.omit(info, 'Company', 'Address')); Â Â Â Â </ script > </ body > Â Â </ html > |
Output:
Example 2:
<!DOCTYPE html> < html > Â Â < head > Â Â Â Â < script type = "text/javascript" src = Â Â Â Â </ script > </ head > Â Â < body > Â Â Â Â < script type = "text/javascript" > Â Â Â Â Â Â Â Â Â Â var info = { Â Â Â Â Â Â Â Â Â Â Â Â key1: 10, Â Â Â Â Â Â Â Â Â Â Â Â key2: 20, Â Â Â Â Â Â Â Â Â Â Â Â key3: 30, Â Â Â Â Â Â Â Â Â Â Â Â key4: 40, Â Â Â Â Â Â Â Â Â Â Â Â key5: 50 Â Â Â Â Â Â Â Â }; Â Â Â Â Â Â Â Â Â Â console.log(_.omit(info, function (value, key, info) { Â Â Â Â Â Â Â Â Â Â Â Â return value == 10 || value == 50; Â Â Â Â Â Â Â Â })); Â Â Â Â </ script > </ body > Â Â </ html > |
Output: