Reputation:
I am trying to alert this array using Firebase Realtime Database:
"discuss" : {
"taj" : {
"20200809" : {
"comment" : "first comment",
"full_date" : "2020/08/09"
}
}
}
I tried to do something like this:
data.val().children.forEach(children => {
alert(children.comment)
});
But came out with nothing. Does anybody have an idea?
Upvotes: 0
Views: 253
Reputation: 80942
If you want to get comment
from the database, then try the following:
let ref = firebase.database().ref("dicuss");
ref.child("taj").on("value", function(snapshot) {
snapshot.forEach(function(childSnapshot) {
var comment = childSnapshot.val().comment;
console.log(comment);
});
});
Add a reference to the node taj
then iterate and retrieve the comment
attribute.
Check the docs:
https://firebase.google.com/docs/database/web/read-and-write
Upvotes: 1