I\’m having an interesting issue that I\’m sure is easily explained, but the explanation is eluding me.
An undefined or null object in javascript is equal to false.
var x;
alert(!x); //returns true
alert(x==true); //returns false
What about an empty array object? Is that the equivalent of true or false?
var x = [];
alert (x==true); //returns false
alert (!x); //returns false
If it is equivalent to true, how do I check if it\’s non-empty? I was hoping to do
if (!x) {
//do stuff
}
I tried checking x.length, but I\’m using this object as a map:
var x = [];
alert(x.length); //returns 0
x.prop = \"hello\";
alert(x.length); //still returns 0
How can I check if my map is empty?





Rating:
The post javascript – javscript empty map appeared first on Javascript ASK.
via Javascript ASK http://javascriptask.phpfogapp.com/javascript-javscript-empty-map.html
No comments:
Post a Comment