UNPKG

1.35 kBJavaScriptView Raw
1import baseFind from './_baseFind';
2import baseForOwnRight from './_baseForOwnRight';
3import baseIteratee from './_baseIteratee';
4
5/**
6 * This method is like `_.findKey` except that it iterates over elements of
7 * a collection in the opposite order.
8 *
9 * @static
10 * @memberOf _
11 * @since 2.0.0
12 * @category Object
13 * @param {Object} object The object to search.
14 * @param {Array|Function|Object|string} [predicate=_.identity]
15 * The function invoked per iteration.
16 * @returns {string|undefined} Returns the key of the matched element,
17 * else `undefined`.
18 * @example
19 *
20 * var users = {
21 * 'barney': { 'age': 36, 'active': true },
22 * 'fred': { 'age': 40, 'active': false },
23 * 'pebbles': { 'age': 1, 'active': true }
24 * };
25 *
26 * _.findLastKey(users, function(o) { return o.age < 40; });
27 * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
28 *
29 * // The `_.matches` iteratee shorthand.
30 * _.findLastKey(users, { 'age': 36, 'active': true });
31 * // => 'barney'
32 *
33 * // The `_.matchesProperty` iteratee shorthand.
34 * _.findLastKey(users, ['active', false]);
35 * // => 'fred'
36 *
37 * // The `_.property` iteratee shorthand.
38 * _.findLastKey(users, 'active');
39 * // => 'pebbles'
40 */
41function findLastKey(object, predicate) {
42 return baseFind(object, baseIteratee(predicate, 3), baseForOwnRight, true);
43}
44
45export default findLastKey;