Saturday, October 25, 2025
HomeLanguagesJavascriptUnderscore.js | _.has() Function

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 is present in the object and False otherwise.

Below examples illustrate the _.has() function in Underscore.js: 

Example 1:  

HTML




<!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>


Output: 

Example 2:  

HTML




<!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(_.has(info, 'Company'));
        console.log(_.has(info, 'Cont'));
    </script>
</body>
 
</html>


Output: 

 

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS