Home

function: get


get(object: Object, path: Array, string, defaultValue: *): *

Gets the value at `path` of `object`. If the resolved value is `undefined`, the `defaultValue` is returned in its place.

Example(s):

const object = { 'a': [{ 'b': { 'c': 3 } }] }

get(object, 'a[0].b.c')
// => 3

get(object, ['a', '0', 'b', 'c'])
// => 3

get(object, 'a.b.c', 'default')
// => 'default'

Params:

Name Type Attribute Description
object The object to query.
path The path of the property to get.
defaultValue The value returned for `undefined` resolved values.

Returns:

*

  {
    "comment": "/**\r\n * Gets the value at `path` of `object`. If the resolved value is\r\n * `undefined`, the `defaultValue` is returned in its place.\r\n *\r\n * @since 3.7.0\r\n * @category Object\r\n * @param {Object} object The object to query.\r\n * @param {Array|string} path The path of the property to get.\r\n * @param {*} [defaultValue] The value returned for `undefined` resolved values.\r\n * @returns {*} Returns the resolved value.\r\n * @see has, hasIn, set, unset\r\n * @example\r\n *\r\n * const object = { 'a': [{ 'b': { 'c': 3 } }] }\r\n *\r\n * get(object, 'a[0].b.c')\r\n * // => 3\r\n *\r\n * get(object, ['a', '0', 'b', 'c'])\r\n * // => 3\r\n *\r\n * get(object, 'a.b.c', 'default')\r\n * // => 'default'\r\n */",
    "meta": {
        "range": [
            725,
            894
        ],
        "filename": "get.js",
        "lineno": 27,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100003111",
            "name": "get",
            "type": "FunctionDeclaration",
            "paramnames": [
                "object",
                "path",
                "defaultValue"
            ]
        },
        "vars": {
            "result": "get~result"
        }
    },
    "description": "Gets the value at `path` of `object`. If the resolved value is\r`undefined`, the `defaultValue` is returned in its place.",
    "since": "3.7.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Object",
            "value": "Object"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Object"
                ]
            },
            "description": "The object to query.",
            "name": "object"
        },
        {
            "type": {
                "names": [
                    "Array",
                    "string"
                ]
            },
            "description": "The path of the property to get.",
            "name": "path"
        },
        {
            "type": {
                "names": [
                    "*"
                ]
            },
            "optional": true,
            "description": "The value returned for `undefined` resolved values.",
            "name": "defaultValue"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "*"
                ]
            },
            "description": "Returns the resolved value."
        }
    ],
    "see": [
        "has, hasIn, set, unset"
    ],
    "examples": [
        "const object = { 'a': [{ 'b': { 'c': 3 } }] }\r\rget(object, 'a[0].b.c')\r// => 3\r\rget(object, ['a', '0', 'b', 'c'])\r// => 3\r\rget(object, 'a.b.c', 'default')\r// => 'default'"
    ],
    "name": "get",
    "longname": "get",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000330",
    "___s": true,
    "filepath": "get.js"
}