3

Is there any solution that allow me to get the name of tables of my database as shown in the picture

database structure

Ali H
  • 903
  • 14
  • 36

1 Answers1

5

You could try something like this:

firebase.database().ref().once('value', function(snapshot) {
    if (snapshot.val() !== null) {
        var tableNames = Object.keys(snapshot.val());
        console.log(tableNames); // ["answers", "blocks", "chats", "classes"]
    }
});

So that gets that whole database and then gets the top level keys from the returned object.

References:

https://firebase.google.com/docs/database/web/read-and-write#read_data_once

In some cases you may want a snapshot of your data without listening for changes, such as when initializing a UI element that you don't expect to change. You can use the once() method to simplify this scenario: it triggers once and then does not trigger again.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

The Object.keys() method returns an array of a given object's own enumerable properties

camden_kid
  • 12,591
  • 11
  • 52
  • 88