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

143
Views
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 answers
Answer question

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 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!