{"-L0bFExUeZXB3-MUXCda":{"Comment":"GOOD","Date":"18 December","User":"OlaNord"}}
{"-L0bFCJh5SPUOWMjTRKu":{"Comment":"ok","Date":"18 December","User":"OlaNord"}}
{"-L0bFA2uzsGDizxxzN1p":{"Comment":"wewwe","Date":"18 December","User":"OlaNord"}}
I have an array of some objects inside. I need to access different values.When I try to retrieve the key name, I get undefined.
Here's my code:
// Path for selected category
var categoryRef = firebase.database().ref("forum/" + currentCategory);
categoryRef.once("value", function(snapshot) {
firebase.auth().onAuthStateChanged(user => {
var key = user.uid;
var postComments = [];
for (var key in snapshot.val()) {
var comments = snapshot.val()[key]['comments'];
postComments.push(comments);
}
})
})

console.log(JSON.stringify(snapshot.val()));