Home

function: property


property(path: Array, string): function

Creates a function that returns the value at `path` of a given object.

Example(s):

const objects = [
  { 'a': { 'b': 2 } },
  { 'a': { 'b': 1 } }
]

map(objects, property('a.b'))
// => [2, 1]

map(sortBy(objects, property(['a', 'b'])), 'a.b')
// => [1, 2]

Params:

Name Type Attribute Description
path The path of the property to get.

Returns:

function

  {
    "comment": "/**\r\n * Creates a function that returns the value at `path` of a given object.\r\n *\r\n * @since 2.4.0\r\n * @category Util\r\n * @param {Array|string} path The path of the property to get.\r\n * @returns {Function} Returns the new accessor function.\r\n * @example\r\n *\r\n * const objects = [\r\n *   { 'a': { 'b': 2 } },\r\n *   { 'a': { 'b': 1 } }\r\n * ]\r\n *\r\n * map(objects, property('a.b'))\r\n * // => [2, 1]\r\n *\r\n * map(sortBy(objects, property(['a', 'b'])), 'a.b')\r\n * // => [1, 2]\r\n */",
    "meta": {
        "range": [
            682,
            785
        ],
        "filename": "property.js",
        "lineno": 26,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100007063",
            "name": "property",
            "type": "FunctionDeclaration",
            "paramnames": [
                "path"
            ]
        }
    },
    "description": "Creates a function that returns the value at `path` of a given object.",
    "since": "2.4.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Util",
            "value": "Util"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "Array",
                    "string"
                ]
            },
            "description": "The path of the property to get.",
            "name": "path"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "Returns the new accessor function."
        }
    ],
    "examples": [
        "const objects = [\r  { 'a': { 'b': 2 } },\r  { 'a': { 'b': 1 } }\r]\r\rmap(objects, property('a.b'))\r// => [2, 1]\r\rmap(sortBy(objects, property(['a', 'b'])), 'a.b')\r// => [1, 2]"
    ],
    "name": "property",
    "longname": "property",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000649",
    "___s": true,
    "filepath": "property.js"
}