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

187
Views
Get value of Firebase DB object as an object and change its keys?

I want to try and get a whole ref from a Firebase Realtime Database into an object, while changing some of its properties:

  const [events, setEvents] = React.useState([]);
  get(child(ref(getDatabase()), `events`)).then(snap => {
   setEvents([snap.val()])
  })
  // creating my object:
  events.map(ev => Object.keys(ev).map(item => ({
    title: ev[item].txt, // the original proparty from firebase is "txt", I wabt to get it as "title"
    image: ev[item].imgUrl,
    description: ev[item].description
  })))

It returned this:

enter image description here

With an extra "0" parent, but how can I get it this way:

enter image description here

This is the json:

  "events" : {
    "-MmZ5gjaPgQZj58NX3Us" : {
      "imgFile" : "77mhw.jpg",
      "imgUrl" : "https://firebasestorage.googleapis.com/v0/b/zevik-4a379.appspot.com/o/77mhw.jpg?alt=media&token=e530272c-6e36-409d-ac68-0042ac17b971",
      "txt" : "sometxt"
    },
    "-MmZ5grbFb-6Bj5ew7Gv" : {
      "imgFile" : "bptmli.jpg",
      "imgUrl" : "https://firebasestorage.googleapis.com/v0/b/zevik-4a379.appspot.com/o/bptmli.jpg?alt=media&token=5f99b26c-e184-43af-bc8b-95484b94f6a5",
      "txt" : "sometxt"
    },
    "-MmZ5gxeoHGTUDZ328RE" : {
      "imgFile" : "xj5fi.jpg",
      "imgUrl" : "https://firebasestorage.googleapis.com/v0/b/zevik-4a379.appspot.com/o/xj5fi.jpg?alt=media&token=7058ea83-1abb-47f7-bcf3-eae2fb2af679",
      "txt" : "sometxt"
    }
  }

Thanks!

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

0

I think the extra 0 level comes from the fact that you use [] in this call:

setEvents([snap.val()])

As far as I can tell that should be:

setEvents(snap.val())
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!