List all the properties!


Oops, try again. It looks like you didn't print the value of nyc's fullNameproperty.

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

// write a for-in loop to print the value of nyc's properties
for(var i in nyc)
    console.log(nyc.i);   //Why this is not working, this is same as nyc.fullName and so on, for each particular iteration 
    console.log(nyc[i]);   //why this works?, this is same as nyc[fullName] which is wrong it should be nyc["fullName"]


Because you are wanting to print the value of each property in nyc. To do this you need to use bracket notation not dot notation. Remove this part from your code.


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