首页 > 编程语言 > 详细

判断Javascript对象是否为空

时间:2017-06-22 14:40:25      阅读:271      评论:0      收藏:0      [点我收藏+]

判断普通javascript对象是否为空(含有可枚举的属性,自有的、继承的都可以),可使用jQuery 3.2.1版的isEmptyObject()方法:

isEmptyObject: function( obj ) {
    var name;
    for ( name in obj ) {
        return false;
    }
    return true;
}

As of jQuery 1.4 this method checks both properties on the object itself and properties inherited from prototypes (in that it doesn‘t use hasOwnProperty). The argument should always be a plain JavaScript Object as other types of object (DOM elements, primitive strings/numbers, host objects) may not give consistent results across browsers. To determine if an object is a plain JavaScript object, use $.isPlainObject()

判断Javascript对象是否为空

原文:http://www.cnblogs.com/sea-breeze/p/7064812.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!