Underscore.js | _.has() Function

The _.has() function is used to check whether the given object contains the given key or not.

Syntax:

_.has(object, key)

Parameters: This function accept two parameters as mentioned above and described below:

  • object: It contains the object element.
  • key: It contains the key that need to be check in the given object.

Return Value: It returns a Boolean value True if the key present in the object and False otherwise.

Below exmaples illustrate the _.has() function in Underscore.js:
Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
  
        var hasFn = _.has({
            Name: 'Ashok',
            Age: 32,
            Email: 'ashok@gfg.com'
        }, 'Age');
  
        console.log(hasFn);
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.