语法:
_.updateWith(object, path, updater, [customizer])
源代码链接:sourcearrow-up-right
npm包链接:npm packagearrow-up-right
描述:
该方法类似
_.updatearrow-up-right,不同之处在于它接受customizer,调用来生成新的对象的path。如果customizer返回undefined,路径创建由该方法代替。customizer调用有三个参数:(nsValue, key, nsObject)。
_.update
customizer
path
undefined
Note:这个方法会改变object.
object
开始版本:4.6.0
参数:
object (Object): 要修改的对象。
object (Object)
path (Array|string): 要设置属性的路径。
path (Array|string)
updater (Function): 用来生成设置值的函数。
updater (Function)
[customizer] (Function): 用来自定义分配值的函数。
[customizer] (Function)
返回值:
(Object): 返回 object.
(Object)
例子:
Last updated 6 years ago
var object = {}; _.updateWith(object, '[0][1]', _.constant('a'), Object); // => { '0': { '1': 'a' } }