判断是否空值
console.log(isNull("false")) // false 字符串不为空
console.log(isNull([])) // true 数组为空
function isNull(obj) {
// 字符串和数组判空
if (obj && obj.length > 0) {
return false;
}
// 按照对应的数据类型进行数据判空
let objType = Object.prototype.toString.call(obj);
// 字符串和数组判空
if (objType === '[object Array]' || objType === '[object String]') {
if (obj && obj.length > 0) {
return false;
}
}
// 如果是对象
if (objType === '[object Object]' && !(JSON.stringify(obj) == "{}")) {
return false;
}
return true;
}
function isNotNull(obj){
return !this.isNull(obj);
}
注意:本文归作者所有,未经作者允许,不得转载