Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

192
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda