2 回答
TA贡献1799条经验 获得超6个赞
第一个条件:
const value = '',
value1 = '',
value2 = '',
value3 = '',
value4 = '',
value5 = '';
const condition1 = [
value,
value1,
value2,
value3,
value4,
value5,
].every(x => x === '');
console.log(`Condition1 : ${condition1}`);
如果您可以将值重构为数组,那就更好了。
const values = [
'',
'',
'',
'',
'',
'',
];
const condition1 = values.every(x => x === '');
console.log(`Condition1 : ${condition1}`);
共
const value = '',
value1 = '',
value2 = '',
value3 = '',
value4 = '',
value5 = '';
if ([
value,
value1,
value2,
value3,
value4,
value5,
].every(x => x === '') || value === 'error') {
console.log(`Condition : true`);
} else {
console.log(`Condition : false`);
}
TA贡献1802条经验 获得超10个赞
为什么不简单地:
if ( (value === '' && value1 === '' && value2 === '' && valu3e === '')
|| value === 'error'
) {
/// ...
}
?
添加回答
举报