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

相關文章
相關標籤/搜索