Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Accessing Firebase value

I am struggling with a simple JSON from Firebase and I am trying to access the value inside it. But can’t seems to wrap my head around, I am trying to access the apiHash and apiId. Any help will be great! Thanks

This is the json retuned by Firebase.

Mv9ALVaVEwa0nGyYWeo:{
apiHash: '6962d35961356a5', 
apiId: 9506201
}

The code to get the json above

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

async function queryData(_mobileNo){
  const ref  = admin.database().ref("users/");
  const snapshot = await ref.orderByChild("mobileNo").equalTo(_mobileNo).once('value');
  return snapshot.val();
}

The Firebase realtime data structure

enter image description here

>Solution :

You can try using Object.values() as shown below:

// data = snapshot.val()
const data = {
  randomKey: {
    apiHash: "value"
  }
};

console.log(Object.values(data)[0]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading