JavaScript判断对象是否是NULL(转)

写js经常会遇到非空判断,看了你不就像风一样的文章

自己没有做总结,特地转载。很有帮助

function isEmpty(obj) {
// 检验 undefined 和 null
    if (!obj && obj !== 0 && obj !== '') {
        return true;
    }
    if (Array.prototype.isPrototypeOf(obj) && obj.length === 0) {
        return true;
    }
    if (Object.prototype.isPrototypeOf(obj) && Object.keys(obj).length === 0) {
        return true;
    }
    return false;
}

作者:像风一样

出处:https://www.cnblogs.com/yueshutong/p/10574211.html

原文地址:https://www.cnblogs.com/niaobulashi/p/10574908.html