Reputation: 297
I´m new to Firebase and I want to access the 'name' and 'score' properties. How could I do this?
I get the whole database like this(following this tutorial), but I dont knwo how I could access the properties of the objects(for example the name of '-Kk50CJUCI...') inside.
scores.on('value', getData, errData)
function getData(data) {
console.log(data.val())
}
function errData (err) {
console.log(err)
}
Thanks! :)
Upvotes: 0
Views: 66
Reputation: 7678
By adding a child_added
event listener, you will get each child node (-Kk50CJUCI.. etc.) individually. You can then directly access the child properties of the data.val()
as below:
scores.on('child_added', getData, errData)
function getData(data) {
console.log(data.val().name)
console.log(data.val().score)
}
function errData (err) {
console.log(err)
}
Upvotes: 1