getObjType = (obj) => {
const type = Object.prototype.toString.call(obj)
const array = type.split(/\s/g)
return array[1].replace(']', '')
}
isEmpty = (obj) => {
const type = getObjType(obj)
console.log('type', type)
let flag = false
switch (type) {
case 'Null':
flag = true
break
case 'Undefined':
flag = true
break
case 'String':
if (obj.trim() === '') {
flag = true
}
break
case 'Array':
if (obj.length === 0) {
flag = true
}
break
default:
flag = false
}
return flag
}
标签:case,判断,obj,true,JavaScript,break,flag,为空,type
From: https://www.cnblogs.com/luckyitape/p/17138122.html