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

108
Vistas
Access value of Firebase RTDB snapshot on value

I need to read the value of the snapshot.val() response. The structure of my Firebase Realtime Database looks like this:

example-default-rtdb
+ 1234567
++ abcdefg
+++ foo: "bar"

Firebase:

const db = firebase.database()
const ref = db.ref('1234567/')

ref.limitToLast(1).on(
  'value',
  snapshot => {
    const response = snapshot.val()
    const message = response.foo
  },
  errorObject => {
    console.log("error")
  }
)

response.foo returns undefined instead of bar. I tried JSON.parse and JSON.stringify - they all return undefined.

This the output if I use const message = JSON.stringify(response, null, ' ')

{
    "123456": {
        "foo": "bar"
    }
}

How to access the value of foo?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

It sounds like you don't know the abcdefg, in which case you can use forEach to loop over all the child nodes of snapshot:

const db = firebase.database()
const ref = db.ref('1234567/')

ref.limitToLast(1).on(
  'value',
  snapshot => {
    snapshot.forEach((child) => {
      console.log(child.key, child.val(), child.val().foo)
    }
  },
  errorObject => {
    console.log("error")
  }
)
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