主题
setWith
js
_.setWith(object, path, value, [customizer])
此方法与 _.set
类似,不同之处在于它接受 customizer
,调用 customizer
可生成 path
的对象。如果 customizer
返回 undefined
,则路径创建由方法处理。customizer
使用三个参数来调用:(nsValue, key, nsObject)。
¥This method is like _.set
except that it accepts customizer
which is invoked to produce the objects of path
. If customizer
returns undefined
path creation is handled by the method instead. The customizer
is invoked with three arguments: (nsValue, key, nsObject).
注意:此方法改变 object
。
¥Note: This method mutates object
.
新增于
¥Since
4.0.0
参数
¥Arguments
object
(对象):要查询的对象。¥
object
(Object): The object to modify.path
(数组|字符串):要设置的属性的路径。¥
path
(Array|string): The path of the property to set.value
(*):要设置的值。¥
value
()*: The value to set.[customizer]
(函数):自定义分配值的函数。¥
[customizer]
(Function): The function to customize assigned values.
返回
¥Returns
(对象):返回 object
。
¥(Object): Returns object
.
示例
¥Example
js
var object = {};
_.setWith(object, '[0][1]', 'a', Object);
// => { '0': { '1': 'a' } }