对象操作

判断对象是否为空

function isEmpty(obj){
    for(var key in obj){
        return false;
    }
    return true;
}
// demo:
isEmpty({});    //true
isEmpty({"key":"value"});    //false
// jq版本
$.isEmptyObject({});    //true
$.isEmptyObject({"key", "value"});    //false

获取对象属性个数

Object.prototype.length = function() {
    var count = 0;
    for(var i in this){
        count ++;
    }
    return count;
};
// demo:
var a = {a:1, b:2, c:3, d:4};
alert(a.length());    // 5
原文地址:https://www.cnblogs.com/iphone6s/p/5031901.html