主题
unset
js
_.unset(object, path)
从 object
中删除 path
处的属性。
¥Removes the property at path
of object
.
注意:此方法改变 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 unset.
返回
¥Returns
(布尔):如果属性被删除,则返回 true
,否则返回 false
。
¥(boolean): Returns true
if the property is deleted, else false
.
示例
¥Example
js
var object = { 'a': [{ 'b': { 'c': 7 } }] };
_.unset(object, 'a[0].b.c');
// => true
console.log(object);
// => { 'a': [{ 'b': {} }] };
_.unset(object, ['a', '0', 'b', 'c']);
// => true
console.log(object);
// => { 'a': [{ 'b': {} }] };