var roominfo = {
'red' : {
'idrooms' : 1,
'occupants' : 0,
'player1' : '',
'player2' : '',
'action' : 1
},
'green' : {
'idrooms' : 2,
'occupants' : 0,
'player1' : '',
'player2' : '',
'action' : 1
},
'blue' : {
'idrooms' : 3,
'occupants' : 0,
'player1' : '',
'player2' : '',
'action' : 1
},
'yellow' : {
'idrooms' : 4,
'occupants' : 0,
'player1' : '',
'player2' : '',
'action' : 1
},
'purple' : {
'idrooms' : 5,
'occupants' : 0,
'player1' : '',
'player2' : '',
'action' : 1
},
'cyan' : {
'idrooms' : 6,
'occupants' : 0,
'player1' : '',
'player2' : '',
'action' : 1
},
};
console.log("logrooms...");
//console.log(roominfo.length);
for (var p in roominfo) {
console.log(p);
if (roominfo.hasOwnProperty(p)) {
// do stuff
console.log(p.idrooms);
console.log(p.occupants);
console.log(p.player1);
console.log(p.player2);
console.log(p.action);
}
}
Here is a link to my jsFiddle: http://jsfiddle.net/sepoto/66nWx/
Each room is entitled a color. So I am able to get to the roomname which in this case turns out to be the variable p. I need to access as well each nested property (idrooms,occupants,player1,player2,action). In my code these are coming up undefined right now.
How do I access the nested properties?
Thank you...