[SOLVED] What is the return value of an EMPTY results?

Hello everyone, I am trying to check if an email address entered on “#input3” is already existed to my Database collection.

So YES it can check and existing email and display an “ERROR” on #textRed, but when the query cannot find anything on the Database Collection so the results is null? or undefined? So if the query cannot find anything on Database it must show “SAVED” on #textRed.

But in my case it doesn’t show, means the results value is “unknown”.
I wish to know the value of results when the query cannot find anything on the Database Collection so I can make an if statement to save or not to save.

Thank you so much!

Just use

if(!results[0].email) {save} else {already exists}

Thanks but it’s not working. When I entered a non existing email, the query won’t pass a result since it does not find an existing email. I just don’t know if it passes a result or a null value. I think the query result wont pass a null value or “empty result”

Then use items.length if it’s 0 means there’s no email if it’s 1 means there’s an email

Use console.log(value) and less frequently console.log(JSON.stringify(value)) and console.log(typeof value) to find out what a function is returning.

Additionally the example in the docs illustrates exactly how to do this.

https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#find

@alvarezcarlosg “Then use items.length if it’s 0 means there’s no email if it’s 1 means there’s an email”
Thank you! :smiley: I got it!