在if语句中是否有“Or”条件的简写,我觉得重复是愚蠢的,在下面的情况下,“a”变量重复检查所有“Or”条件:
if(a != 'Cancelled' || a != 'Rejected' || a != 'Delivered' || a != 'Confirmed'){
//execute something here
}
答案 0 :(得分:3)
if (['Cancelled', 'Rejected', 'Delivered', 'Confirmed'].indexOf(a) == -1) {
// do stuff here
}