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