lundi 26 juillet 2021

why isn't an empty array considered as false? [duplicate]

I have a chosenDocumentItemsIds array which I want to make condition based on its length. When I write

   if (this.chosenDocumentItemsIds) {
       console.log('true');
   } else {
       console.log('false');
   }

true is logged in the console even though this.chosenDocumentItemsIds = []; and if I want false to be shown, I have to write if (this.chosenDocumentItemsIds.length). I thought empty arrays must be false! why they aren't?

Aucun commentaire:

Enregistrer un commentaire