Home

function: findKey


findKey(object: Object, predicate: function): string, undefined

This method is like `find` except that it returns the key of the first element `predicate` returns truthy for instead of the element itself.

Example(s):

const users = {
  'barney':  { 'age': 36, 'active': true },
  'fred':    { 'age': 40, 'active': false },
  'pebbles': { 'age': 1,  'active': true }
}

findKey(users, ({ age }) => age < 40)
// => 'barney' (iteration order is not guaranteed)

Params:

Name Type Attribute Description
object The object to inspect.
predicate The function invoked per iteration.

Returns:

string, undefined

  {
    "comment": "/**\r\n * This method is like `find` except that it returns the key of the first\r\n * element `predicate` returns truthy for instead of the element itself.\r\n *\r\n * @since 1.1.0\r\n * @category Object\r\n * @param {Object} object The object to inspect.\r\n * @param {Function} predicate The function invoked per iteration.\r\n * @returns {string|undefined} Returns the key of the matched element,\r\n *  else `undefined`.\r\n * @see find, findIndex, findLast, findLastIndex, findLastKey\r\n * @example\r\n *\r\n * const users = {\r\n *   'barney':  { 'age': 36, 'active': true },\r\n *   'fred':    { 'age': 40, 'active': false },\r\n *   'pebbles': { 'age': 1,  'active': true }\r\n * }\r\n *\r\n * findKey(users, ({ age }) => age < 40)\r\n * // => 'barney' (iteration order is not guaranteed)\r\n */",
    "meta": {
        "range": [
            765,
            1051
        ],
        "filename": "findKey.js",
        "lineno": 23,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100002377",
            "name": "findKey",
            "type": "FunctionDeclaration",
            "paramnames": [
                "object",
                "predicate"
            ]
        },
        "vars": {
            "result": "findKey~result",
            "": null
        }
    },
    "description": "This method is like `find` except that it returns the key of the first\relement `predicate` returns truthy for instead of the element itself.",
    "since": "1.1.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Object",
            "value": "Object"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Object"
                ]
            },
            "description": "The object to inspect.",
            "name": "object"
        },
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The function invoked per iteration.",
            "name": "predicate"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "string",
                    "undefined"
                ]
            },
            "description": "Returns the key of the matched element,\r else `undefined`."
        }
    ],
    "see": [
        "find, findIndex, findLast, findLastIndex, findLastKey"
    ],
    "examples": [
        "const users = {\r  'barney':  { 'age': 36, 'active': true },\r  'fred':    { 'age': 40, 'active': false },\r  'pebbles': { 'age': 1,  'active': true }\r}\r\rfindKey(users, ({ age }) => age < 40)\r// => 'barney' (iteration order is not guaranteed)"
    ],
    "name": "findKey",
    "longname": "findKey",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000262",
    "___s": true,
    "filepath": "findKey.js"
}