Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda