Write a function in js to determine whether a value is empty

Write a function in js to determine whether a value is empty.
Here, special consideration should be given to the special processing when a value is 0, an empty array, or an empty object.
Note: In many cases, 0 should not be judged as empty.

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
		}
	}
}

Guess you like

Origin blog.csdn.net/qq_17355709/article/details/133215013