Prints out the propertys but not its values


#1

var nyc = {
fullName: "New York City",
mayor: "Bill de Blasio",
population: 8000000,
boroughs: 5
};
for (var fullName in nyc) {
console.log(fullName);
};

when i used that code, it prints out the propertys but not its values


9. getting INtimate
#2

In loops it is a good idea to use a generic iterator variable that is not one of the property names.

for (var detail in nyc) {
    console.log(detail + ": " + nyc[detail]);
}

detail is a placeholder variable to receive the property names (keys). nyc[detail] is the value for each property.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.