Alaa
Alaa

Reputation: 25

read child of child in firebase web (javascript)

I am new in firebase, how can i read child as in the image to my web page anyone can tell me if there is a reference?

enter image description here

Upvotes: 1

Views: 672

Answers (2)

Hasanuzzaman
Hasanuzzaman

Reputation: 618

If you want to get the value only when your data is in an object, then you can use

var ref = firebase.database().ref();     //creating referense path
ref.once("value").then(data=>{
    let obj = data.val();
    for (let key in obj) {
        console.log(obj[key]);
    }   
})

Upvotes: 0

Frank van Puffelen
Frank van Puffelen

Reputation: 600126

If you want to read all colors of all nodes:

var ref = firebase.database().ref();
ref.once("value").then(function(snapshot) {
    snapshot.forEach(function(childSnapshot) {
        childSnapshot.forEach(function(colorSnapshot) {
            console.log(childSnapshot.key+" - "+colorSnapshot.key+": "+colorSnapshot.val());
        });
    });
});

This prints:

-LOIECwM70... - 1: red

-LOIECwM70... - 2: blue

-LOIEssdh1... - 1: green

-LOIEssdh1... - 1: black

Upvotes: 2

Related Questions