Lodash _.unset()方法用于删除对象路径处的属性。如果该属性被删除,则返回True值,否则返回False。
用法:
_.unset(object, path)
参数:此方法接受上面提到和下面描述的两个参数:
- object:此参数保存要修改的对象。
- path:此参数保存要设置的属性的路径。它可以是数组或字符串。
返回值:如果属性被删除,则此方法返回true,否则返回false。
范例1:
Javascript
// Requiring the lodash library
const _ = require("lodash");
// The source object
var obj = { 'cpp':[{ 'java':{ 'python':3 } }] };
// Use of _.unset() method
console.log(_.unset(obj, 'cpp[0].java.python'));
// Object is modified
console.log(obj);
输出:
true { cpp:[ { java:{} } ] }
范例2:
Javascript
// Requiring the lodash library
const _ = require("lodash");
// The source object
var obj = { 'cpp':[{ 'java':{ 'python':3 } }] };
// Use of _.unset() method
console.log(_.unset(obj, ['html', 'css', 'javascript']));
// Object
console.log(obj);
输出:
true { cpp:[ { java:[Object] } ] }
注意:在正常的JavaScript中这将无法正常工作,因为它需要安装库lodash并可以使用安装npm安装lodash。。
相关用法
- PHP unset()用法及代码示例
- PHP Unset() vs Unlink()用法及代码示例
- Lodash _.method()用法及代码示例
- Lodash _.sneq()用法及代码示例
- Lodash _.toQuery()用法及代码示例
- Lodash _.uniqWith()用法及代码示例
- Lodash _.xorWith()用法及代码示例
- Lodash _.head()用法及代码示例
- Lodash _.remove()用法及代码示例
- Lodash _.pullAt()用法及代码示例
- Lodash _.pullAll()用法及代码示例
- Lodash _.pull()用法及代码示例
- Lodash _.nth()用法及代码示例
- Lodash _.takeRight()用法及代码示例
- Lodash _.take()用法及代码示例
- Lodash _.sortedLastIndex()用法及代码示例
- Lodash _.fromPairs()用法及代码示例
注:本文由纯净天空筛选整理自sanjoy_62大神的英文原创作品 Lodash _.unset() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。