js 如何删除对象中的一个属性
Deleting Properties
The only way to actually remove a property from an object is to use thedelete operator;
setting the property to undefined or null only
remove the value associated
with the property, but not the key.
var obj = {
bar: 1,
foo: 2,
baz: 3
};
obj.bar = undefined;
obj.foo = null;
delete obj.baz;
for(var i in obj) {
if (obj.hasOwnProperty(i)) {
console.log(i, "" + obj[i]);
}
}
The above outputs both bar
undefined and foo
null - only baz was
removed and is therefore missing from the output.
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了
