天天看点

JavaScript中提供的for...in遍历对象

for … in 遍历对象

var person = {
    name:"小明",
    score:,
    gender:"male";

    sleep:function(){
      console.log("小明在休息");
   }
}
           

如果要遍历小明的这个对象,可以使用以下方法

for(var x in student){
    console.log(x);       //输出student的定义的属性 方法  方式值没被输出
    console.log(student[x]); //输出student的属性值 方法值
    console.log(x+"是"+student[x]); //输出score是99...
}
           

继续阅读