JS如何删除一个对象的属性
2018-12-19 本文已影响0人
bryan_liu
思路是采用delete方法:
var obj = {name:"fjj",age:18};
//添加属性
obj.gender = "women";
//输出结果 {name:"fjj",age:18,gender:"women"};
delete obj.gender;
//输出结果 {name:"fjj",age:18};
运行结果思路是采用delete方法:
var obj = {name:"fjj",age:18};
//添加属性
obj.gender = "women";
//输出结果 {name:"fjj",age:18,gender:"women"};
delete obj.gender;
//输出结果 {name:"fjj",age:18};
运行结果