findKey
_.findKey(predicate, object)
# Ⓢ [Ⓣ][1] Ⓝ
This method is like _.find except that it returns the key of the first
element predicate returns truthy for instead of the element itself.
Since
1.1.0
Arguments
predicate(Function): The function invoked per iteration.object(Object): The object to inspect.
Returns
(*): Returns the key of the matched element,
else undefined.
Example
var users = {
'barney': { 'age': 36, 'active': true },
'fred': { 'age': 40, 'active': false },
'pebbles': { 'age': 1, 'active': true }
};
_.findKey(function(o) { return o.age < 40; }, users);
// => 'barney' (iteration order is not guaranteed)
// The `_.matches` iteratee shorthand.
_.findKey({ 'age': 1, 'active': true }, users);
// => 'pebbles'
// The `_.matchesProperty` iteratee shorthand.
_.findKey(['active', false], users);
// => 'fred'
// The `_.property` iteratee shorthand.
_.findKey('active', users);
// => 'barney'