1. Determine whether NaN (NaN (not a number) belongs to the Number type)
isNaN (the field that needs to be judged)
2. Determine whether it is undefined (field is undefined)
typeof (field to be judged) == "undefined"
3. Determine whether it is null (the field is defined but has no value)
function isNull(value) {
if (value === null) { // 是三等号操作符(===)而不是双等号
return true;
} else {
return false;
}
}
Method Two:
function isNull(value) {
if (!value && typeof value != "undefined" && value != 0) {
return true;
} else {
return false;
}
}
typeof 参数 != "undefined" 排除了 undefined;
参数 != 0 排除了数字零和 false。
4. Determine whether the attributes of a row in the array are all null values (filter blank rows), and determine whether the attributes in the object are all null values
data.forEach((v,i) => {
if (i>0) {
const keys = Object.keys(v)
const allNull = Object.values(v).filter(obj=> obj=='') // 判断一行中是否每个属性都是空数据, 过滤空行
// console.log('allNull', allNull, allNull.length, keys.length, keys);
if (allNull.length !== keys.length) { // 一行中所有属性都是空值
console.log('一行中所有属性都是空值')
}
}
})