Lodash教程

Lodash update method

语法

_.update(object, path, updater)
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).

参数

object (Object) − The object to modify. path (Array|string) − The path of the property to set. updater (Function) − The second number in an addition.

输出

(Object) − Returns object.

实例

var _ = require('lodash');
var object = { 'a': [{ 'b': { 'c': 3 } }] };
_.update(object, 'a[0].b.c', function(n) { return n * n; });
console.log(object.a[0].b.c);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

9
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4