good_evening good_evening - 1 year ago 254
Javascript Question

Firebase get key value

It's easy to get value:

firebase_instance.limit(100).on("child_added", function(data) {
var value = data.val();

but how to get a key associated with that value?

Answer Source

Each of your Firebase .on(...) callbacks are going to be invoked with a Firebase DataSnapshot. To get the name for the location of that DataSnapshot, try using the name() method.

For example:

firebase_instance.limit(100).on("child_added", function(snap) {
  var name =;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download