I am curious to know if you can place a for/in loop inside a for/in loop the way you can with a standard for loop. In the example below I am trying to list all of the properties of each game object but I am not getting the expected result. I have tried using dot notation and square brackets but neither seems to work. Is this not possible or am I overlooking something simple in the syntax?
var games = [{
"name": "PCH Mystery Game",
"maxScore": 50000,
"levels": 4,
"players": ["akshat", "joe", "dandan", "andrew"],
"maps": {
"1": 1,
"2": 2,
"3": 3,
"4": 4
}
},
{
"name": "PCH Token Dash",
"maxScore": 11500,
"levels": 2,
"players": ["andrew", "dandan", "matt", "mitchell", "hadi"],
"maps": {
"1": 1,
"2": 2,
"3": 3,
"4": 4
}
},
{
"name": "PCH Balloon Drop",
"maxScore": 500,
"levels": 1,
"players": [
"akshat", "joe", "dandan", "dan", "mark", "nagesh", "jessie", "lou"
],
"maps": {
"1": 1,
"2": 2,
"3": 3,
"4": 4
}
},
{
"name": "PCH Envelope Toss",
"maxScore": 7000,
"levels": 84,
"players": ["akshat", "jessie", "joe", "andrew", "dandan"],
"maps": {
"1": 1,
"2": 2,
"3": 3,
"4": 4
}
},
{
"name": "PCH Prize Patrol Race",
"maxScore": 100000,
"levels": 5,
"players": [
"akshat", "joe", "andrew", "dandan", "lou", "roberto", "jessie", "haim", "matt", "mitchell", "ian"
],
"maps": {
"1": 1,
"2": 2,
"3": 3,
"4": 4
}
}
];
for (game in games) {
document.write("game: " + games[game].name + "<br>");
for (prop in game) {
document.write("property name: " + prop + "<br>");
document.write("property value: " + game[prop] + "<br>");
document.write("property value: " + game.prop + "<br>");
}
document.write("<br>");
}