let arr = [];
if (arr.length == 0){
console.log("数组为空")
}else {
console.log("数组不为空")
}
if(JSON.stringify(response.data) == "{}")
var data = {};
var b = (JSON.stringify(data) == "{}");
console.log(b); //true
2.for in 循环判断
如果是空对象返回true, 否则返回 false 。
var obj = {};
var b = function() {
for(var key in obj) {
return false; //不为空
}
return true;
}
console.log(b()); //true
3.使用ES6的Object.keys()方法
var data = {};
var arr = Object.keys(data);
console.log(arr.length == 0); //true