js—对象的操作

枚举对象属性

var myObj = {
  name:'gongjialin',
  sex:'woman',
  myFun:function(){
    console.log("this is test")
  }
}
for(var data in myObj){
  document.write('style--'+data+","+value+"myObj[data]")
}

增删属性和方法

var myObj = {
    name:'jialin',
    sex:"woman',
}
//增加属性
myObj.age = 23
//删除属性
delete myObj.sex;

检测对象是否具有某个属性

var myObj = {
    name:'jialin',
    sex:"woman',
}
var hasName = 'name'  in myObj;   //true
var hasAge = 'age' in myObj;  //false;

你可能感兴趣的:(js—对象的操作)