vendredi 28 juin 2019

Checking For Empty Array in If/Else Block Strange Behavior

Within my if/else block, I wanted to check if a certain array is empty by using:

else if (emptyFieldNames.length === 0) {
  console.log('no empty fields');
}

I've consoled log 'emptyFieldNames' and can verify it is empty, but the code body won't run**.

If you fill in all input fields here in this codepen, and click submit, you'll see it console logging an empty array, but yet not logging the message. The interesting part is, **if you fill in a valid email, it will console log the message. However, I don't see why that would matter since array is still empty whether or not a valid email is inputted.

What am I missing?

Aucun commentaire:

Enregistrer un commentaire