Realtimedatabase Read data via Java Script

Asked

Viewed 21 times

0

I have the following JSON

  "colecao" : {
    "id" : {
      "subid1" : 2,
      "subid2" : 1
    }
  }

I use the following commands to retrieve data from the Altime

    var dbrealtime = firebase.database(); 
    var query = dbrealtime.ref('colecao');
    query.on('value', function(snapshot) {
    console.log(snapshot.val().id);

});

If I do it will take the value "2";

console.log(snapshot.val().id.subid1);

I would like to do a foreach and show the two values that have in id without having to reference subid1 and subid2.

Example:

2

1

1 answer

0


You can use Jquery to do this, with the following code:

$.each(snapshot.val().id, function(index, element) {
    console.log(element);
});

You can read the documentation of this function here:

https://api.jquery.com/each/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.