判断 js 数组是否为 empty

function isEmpty(obj) {
    for(var key in obj) {
       if(obj.hasOwnProperty(key))
           return false;
       }
    return true;
}
var mycars = new Array();
mycars[0] = "";
mycars[1] = "";
mycars[2] = "";
console.log(isEmpty(mycars) ? '0' : '1'),

 

 

资料来源:

https://coderwall.com/p/_g3x9q/how-to-check-if-javascript-object-is-empty

posted @ 2019-01-03 15:16  Ryan_zheng  阅读(7882)  评论(0编辑  收藏  举报