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

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

本身没有作总结,特意转载。颇有帮助spa

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;
}

做者:像风同样prototype

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

相关文章
相关标签/搜索