您的位置:首页 > Web前端 > JavaScript

js判断对象为空

2016-06-21 13:50 429 查看
http://www.jb51.net/article/42713.htm

var isEmptyValue = function(value) {
var type;
if(value == null) { // 等同于 value === undefined || value === null
return true;
}
type = Object.prototype.toString.call(value).slice(8, -1);
switch(type) {
case 'String':
return !$.trim(value);
case 'Array':
return !value.length;
case 'Object':
return $.isEmptyObject(value); // 普通对象使用 for...in 判断,有 key 即为 false
default:
return false; // 其他对象均视作非空
}
};


其中 isEmptyObject

function isEmptyObject(e) {
var t;
for (t in e)
return !1;
return !0
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: