I have code like this, then I was confused on how to loop the array family to print each member under person.
function Person(name,age){
this.name = name;
this.age = age;
}
var family = [];
family[0] = new Person("alice",40);
family[1] = new Person("bob",42);
family[2] = new Person("michelle",8);
family[3] = new Person("timmy",6);
here is a JsFiddle
is that what you need ?
for (var key in family) {
var obj = family[key];
for (var prop in obj) {
alert(prop + " = " + obj[prop]);
}
}
Here is the way to access the properties directly and not with a loop jsFIddle (Method 2, uncomment)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With