This method is like `set` except that accepts `updater` to produce the value to set. Use `updateWith` to customize `path` creation. The `updater` is invoked with one argument: (value). **Note:** This method mutates `object`.
const object = { 'a': [{ 'b': { 'c': 3 } }] }
update(object, 'a[0].b.c', n => n * n)
console.log(object.a[0].b.c)
// => 9
update(object, 'x[0].y.z', n => n ? n + 1 : 0)
console.log(object.x[0].y.z)
// => 0
Name | Type | Attribute | Description |
---|---|---|---|
object | The object to modify. | ||
path | The path of the property to set. | ||
updater | The function to produce the updated value. |
{ "comment": "/**\r\n * This method is like `set` except that accepts `updater` to produce the\r\n * value to set. Use `updateWith` to customize `path` creation. The `updater`\r\n * is invoked with one argument: (value).\r\n *\r\n * **Note:** This method mutates `object`.\r\n *\r\n * @since 4.6.0\r\n * @category Object\r\n * @param {Object} object The object to modify.\r\n * @param {Array|string} path The path of the property to set.\r\n * @param {Function} updater The function to produce the updated value.\r\n * @returns {Object} Returns `object`.\r\n * @example\r\n *\r\n * const object = { 'a': [{ 'b': { 'c': 3 } }] }\r\n *\r\n * update(object, 'a[0].b.c', n => n * n)\r\n * console.log(object.a[0].b.c)\r\n * // => 9\r\n *\r\n * update(object, 'x[0].y.z', n => n ? n + 1 : 0)\r\n * console.log(object.x[0].y.z)\r\n * // => 0\r\n */", "meta": { "range": [ 836, 949 ], "filename": "update.js", "lineno": 28, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100011484", "name": "update", "type": "FunctionDeclaration", "paramnames": [ "object", "path", "updater" ] } }, "description": "This method is like `set` except that accepts `updater` to produce the\rvalue to set. Use `updateWith` to customize `path` creation. The `updater`\ris invoked with one argument: (value).\r\r**Note:** This method mutates `object`.", "since": "4.6.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Object", "value": "Object" } ], "params": [ { "type": { "names": [ "Object" ] }, "description": "The object to modify.", "name": "object" }, { "type": { "names": [ "Array", "string" ] }, "description": "The path of the property to set.", "name": "path" }, { "type": { "names": [ "function" ] }, "description": "The function to produce the updated value.", "name": "updater" } ], "returns": [ { "type": { "names": [ "Object" ] }, "description": "Returns `object`." } ], "examples": [ "const object = { 'a': [{ 'b': { 'c': 3 } }] }\r\rupdate(object, 'a[0].b.c', n => n * n)\rconsole.log(object.a[0].b.c)\r// => 9\r\rupdate(object, 'x[0].y.z', n => n ? n + 1 : 0)\rconsole.log(object.x[0].y.z)\r// => 0" ], "name": "update", "longname": "update", "kind": "function", "scope": "global", "___id": "T000002R001042", "___s": true, "filepath": "update.js" }