Return to Snippet

Revision: 63179
at April 14, 2013 07:29 by Tim_McClure


Initial Code
var nyc = {
    fullName: "New York City",
    mayor: "Michael Bloomberg",
    population: 8000000,
    boroughs: 5
};


for (var property in nyc){
    console.log(property);
}

Initial URL


Initial Description
What this does is prints out every property within the object, rather than having to write the code for printing out each specific property. 

In English, what is the code doing? It says: Assign the first property of the dog object to the variable property. Run the code (here, it is to print property to console). Then assign the second property of the dog object to the variable property. Again, run the code in the curly brackets. Keep repeating this until all the properties of the dog have been assigned to property.

Initial Title
For-In Loops with Objects

Initial Tags


Initial Language
JavaScript