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 Shivam Sharma for Why do empty JavaScript arrays evaluate to true in conditional structures?

$
0
0

As in JavaScript, everything is an object so for falsy and empty, I use the below condition:

if(value && Object.keys(value).length){    // Not falsy and not empty}else{    // falsy or empty array/object}

Viewing all articles
Browse latest Browse all 8

Trending Articles



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