How to judge whether an array is empty?

来源:互联网 发布:tomcat 多域名设置 编辑:程序博客网 时间:2024/04/30 20:03

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 ==....
0 0
原创粉丝点击