Open In App

Underscore.js _.omit() Function

Improve
Improve
Like Article
Like
Save
Share
Report

Underscore.js _.omit() function is used to return a copy of the object that was filtered to omit the blacklisted keys.

Syntax:

_.omit(object, *keys);

Parameters:

  • object: This parameter holds the value of an object.
  • keys: It is an optional parameter. It contains the key name that the value needs to be omitted.

Return Value:

It returns a copy of the object that was filtered to omit the blacklisted keys.

Example 1: In this example, we are using the Underscore.js _.omit() function.

html




<!DOCTYPE html>
<html>
 
<head>
    <script type="text/javascript" src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        let info = {
            Company: 'GeeksforGeeks',
            Address: 'Noida',
            Contact: '+91 9876543210'
        };
 
        console.log(_.omit(info, 'Company', 'Address'));
    </script>
</body>
 
</html>


Output:

Example 2: In this example, we are using the Underscore.js _.omit() function.

html




<!DOCTYPE html>
<html>
 
<head>
    <script type="text/javascript" src=
    </script>
</head>
 
<body>
    <script type="text/javascript">
 
        let 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:



Last Updated : 14 Jan, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads