Open In App
Related Articles

Underscore.js _.findKey() Function

Improve Article
Improve
Save Article
Save
Like Article
Like

The _.findKey() function is used to return the key value where the predicate logic or condition returns the truth value or undefined. The predicate function/condition is transformed through iteratee to facilitate shorthand syntaxes.

Syntax:

_.findKey(object, predicate, [context])

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

  • list: This parameter is used to hold the list of items.
  • predicate: This parameter is used to hold the truth condition.
  • context: The text content which need to be display. It is optional parameter.

Return Value: It returns the key value where the predicate logic or condition returns truth or undefined.

Example 1:




<!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'
        };
  
        var key = _.findKey(info, function (value) {
            return value === 'GeeksforGeeks';
        });
          
        console.log(key);
    </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: 'Geeks',
            key2: 'GFG',
            key3: 'GeeksforGeeks',
            key4: 'Hello',
            key5: 'Welcome'
        };
  
        var key = _.findKey(info, function (value) {
            return value.length == 13;
        });
  
        console.log(key);
    </script>
</body>
  
</html>


Output:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 25 Nov, 2021
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials