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:
html
Output:
Example 2:
html
_.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.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</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>
Example 2:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</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:

