Is there any solution that allow me to get the name of tables of my database as shown in the picture
Asked
Active
Viewed 2,804 times
3
-
There are many, many ways to do so. Did you try anything yet? What's the problem you bumped into? – Frank van Puffelen Oct 23 '17 at 14:38
-
@FrankvanPuffelen I will be happy if u help me and share me any links or codes that solve my problem .. – Ali H Oct 23 '17 at 14:42
-
Please add what you have tried, some code will go a long way. – alphapilgrim Oct 23 '17 at 14:55
1 Answers
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