如何跳过school判断name和age和sex是否为空,如果为空返回false,否则true
let obj={
name:'',
age:0,
sex:'男',
school:'南校'
}
function hasNull(obj) {//name,age或者sex其中有一个存在等价于false的值返回true
return !obj.name || !obj.age || !obj.sex ? true : false;
}
console.log(hasNull({ name: '', age: 0, sex: '男', school: '南校' }));//true
console.log(hasNull({ name: 'xx', age: 0, sex: '男', school: '南校' }));//true
console.log(hasNull({ name: 'xx', age: 19, sex: '男', school: '南校' }));//false
其中一个为空就返回false return obj.name&&obj.age&&obj.sex;
全部为空才返回false return obj.name || obj.age||obj.sex;