Prints out the propertys but not its values


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

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

9. getting INtimate

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.


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