Noman Ali Noman Ali - 3 years ago 195
Javascript Question

Parsing firebase object javascript

It might be duplicate, sorry for that but I couldn't understand (New to firebase and JS).

I have a snapshot from firebase, but I couldn't understand how to parse that snapshot object.

Here is my code:

var obj = snapshot.val();

It outputs following:


I want to get this
value in a separate variable and
into separate variable, but not be able to.

What should I do?

Answer Source

To get the key name and its chatid value:

var json = {
  "-KpxDFnJEt2xlD21lzyh": {
    "chatid": "6qKi8xO5vxdrcKFd5wqUNUkTupg2PNQjC87cFNcKxYkDoYMdhH95LCK2"
for (key in json) {
  if (!json.hasOwnProperty(key)) continue;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download