标签:键值 创建 log only TE weight let delete 输出
结论:字面量方式创建的对象和构造函数创建的对象都可以用delete关键字删除
1.字面量方式
var bonly={
name:‘bonly‘,
age:"18",
weight:‘70kg‘
};
for (var k in bonly) {
if(k==‘age‘){
delete bonly[k];
}
}
console.log(bonly);
// 输出 bonly={name:"bonly",weight:"70kg"};
2.构造函数创建
var bonly=new Object();
bonly.name="bonly";
bonly.age="18";
bonly.weight="70kg";
for (var k in bonly) {
if(k==‘age‘){
delete bonly[k];
}
}
console.log(bonly);
// 输出 bonly={name:"bonly",weight:"70kg"};
标签:键值 创建 log only TE weight let delete 输出
原文地址:https://www.cnblogs.com/bonly-ge/p/9206652.html