1、for in 循环
eg:var obj = {}
var b = function () {
for (var key in obj) {
return false;
}
return true;
}
console.log(b()); // true
2、对象序列化(将对象转换为字符串)后进行判断
eg:var data = {};
var b = (JSON.stringify(data) == "{}");
console.log(b); // true
3、jquery的isEmptyObject()方法
eg: var data = {};
var b = $.isEmptyObject(data);
console.log(b); // true
4、Object.getOwnPropertyNames()方法
eg: var data = {};
var arr = Object.getOwnPropertyNames(data);
console.log(arr.length == 0); // true
5、ES6中的Object.keys()方法
eg: var data = {};
var arr = Object.keys(data);
console.log(arr.length == 0); // true
网友评论