结论:字面量方式创建的对象和构造函数创建的对象都可以用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"};