Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

366
Views
Getting the Data in snapshot.val() but not able to treat it

I was making an app and had to fetch data from Realtime Database. I am getting the data in snapshot.val() like this

►{xz0ezxzrpkb:{…}}
▼xz0ezxzrpkb:{blood_group:"B+",cause:"Random Cause",created_on:"08-02-2022",email:"example@gmail.com",location:"Random Location",message:"Random Message",name:"Any_Name",phone_number:"+91 *********"}

And Now I want to access this data. When I am trying snapshot.val()[0].email and
snapshot.val().[0].email I am Getting

undefined (2)

So, I am working in React Native and this is the code

db.ref('/requests/').on('value', (snapshot) => {
       console.log(snapshot.val())
       console.log(snapshot.val()[0].email)
       console.log(snapshot.val().[0].email)
});

The nodes of database are as follows: enter image description here

Please help me out.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The snapshot value is not an object. Try refactoring the code using Object.keys() as shown below:

db.ref('/requests/').on('value', (snapshot) => {
  Object.keys(snapshot.val()).forEach((key) => {
    const request = snapshot.val()[key];
    console.log(key, request.email)
  })
});
about 4 years ago · Juan Pablo Isaza Report

0

While the approach in Dharmaraj's answer works, I recommend using Firebase's built-in forEach operation, since that ensures that you process the results in the same order the database returns them:

db.ref('/requests/').on('value', (snapshot) => {
  snapshot.forEach((childSnapshot) => {
     console.log(childSnapshot.key)                  // "xz0ezxzrpkb"
     console.log(childSnapshot.val())                // {blood_group:"B+",cause:"Random Cause", ...
     console.log(childSnapshot.val().email)          // "example@gmail.com"
     console.log(childSnapshot.child('email').val()) // "example@gmail.com"
  })
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!