Imagine you have this JavaScript object retrieved from a Firebase query.
{
"player": {
"player:616320": {
"skills": {
"main": {
"attack": 1,
"defence": 1
}
},
"uid": "player:616320",
"username": "test1",
"x": 1,
"y": 1
}
}
}
var data = snap.val();
You can easily access data.username
to retrieve test1
, but how do you dig deeper? JSON nesting can be confusing when trying to get values like attack
nested under main
.
Remember, snap.val()
is the JSON object provided above. How can you extract the value of attack
within main
?