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

144
Vistas
Firebase - checking if field exits

In my firebase DB I have:

A User model and a field called username.

This username could either exist or be "" When I say exist I mean that that field might not exist under the User 'yet'.

Im doing a check:

if (username || username != "")
    //show some stuff here

if the username field DOES NOT exist the above still shows some stuff

if the field doesn't exist when I log it it comes back as undefined

I have tried this:

if (username != undefined || username != "")
    //show some stuff here

The above also shows some stuff

Im trying to have it so if the username exists and isNot an empty string then show stuff

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

0

If any field is missing then it's undefined for sure. That if-else statement should work:

const data = snapshot.val()
const username = data.username

if (username) {
  console.log("username is present")
} else {
  console.log("Username is absent")
}

I cannot see where that 'username' is coming from. If the above still doesn't work then please share the complete code so we can check if there's any mistake apart from the provided snippet in question.

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