Quantcast
Channel: Why do empty JavaScript arrays evaluate to true in conditional structures? - Stack Overflow
Viewing all articles
Browse latest Browse all 8

Answer by DevlshOne for Why do empty JavaScript arrays evaluate to true in conditional structures?

$
0
0

You should be checking the .length of that array to see if it contains any elements.

if (myCollection) // always trueif (myCollection.length) // always true when array has elementsif (myCollection.length === 0) // same as is_empty(myCollection)

Viewing all articles
Browse latest Browse all 8

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>