您的位置:首页 > 其它

How to judge whether an array is empty?

2016-09-07 23:21 447 查看
Today I got an array from database.Before I used it,I first judged it.But I made a mistake,I used if(arr).I forgot an array is an object…

So if we want to judge whether an array is empty.take following measures:

var arr=[];
if(arr == "")//object will change to string and an empty array returns  ""
{
//code goes here
}


or

var arr=[];
if(arr.length===0)//I recommend this for I do not want to use ==.
...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: