让我们说:
function person(){
this.name = null;
this.lastname = null;
this.age = null;
this.height = null;
}
如何迭代属性?
类似的东西:
foreach(properties as property){
console.log ( property.nameoftheproperty, property.valueoftheproperty);
}
答案 0 :(得分:2)
您可以使用for..in
循环,就像这样
function Person(){
this.name = null;
this.lastname = null;
this.age = null;
this.height = null;
}
var person = new Person();
for (var key in person) {
console.log(key, person[key]);
}
<强>输出强>
name null
lastname null
age null
height null
答案 1 :(得分:0)
for(var prop in properties) {
console.log(properties[prop]);
}