javascript中怎么判断对象{}为空 - 2350305682 - 博客园
static isObjectType(obj) {
return obj instanceof Object;
}
static isEmptyObject(obj) {
/**
* 1、判断obj是否为空对象{}最完美的方法【务必注意:{}的布尔值为true,否则必须转换】
*/
if (!isObjectType(obj)) {
return false;
}
let check_result = true;
for (let i in obj) {
check_result = false;
}
return check_result;
}
# 以下两个方法都Bug【如果obj=1这类值,依然为true】
Boolean(obj && (Object.getOwnPropertyNames(obj).length === 0));
Boolean(UtilArrayObject.isEmptyArray(Object.keys(obj)));