Escriba una función en js para determinar si un valor está vacío.
Aquí, se debe prestar especial atención al procesamiento especial cuando un valor es 0, una matriz vacía o un objeto vacío.
Nota: En muchos casos, 0 no debe considerarse vacío.
export const isNull = (value) => {
if (value === 0) {
// 若不去单独处理0,0为被默认判定为空,所以这里特殊处理0为非空
return false
} else {
if (typeof value == 'object') {
// 这里单独判断空数组和空对象
if (value.length <= 0 || Object.keys(value).length <= 0) {
return true
} else {
return false
}
} else if (value === '' || value === 'undefined' || value === undefined || value === null || value === 'null') {
return true
} else {
return false
}
}
}