我如何通过单一<条码>实现这一点? 换言之,if(fruit !”“apple > fruit fruit!”=“range”=
不是产生预期的结果?
fruits.forEach(function(fruit){
if(fruit != "apple"){ // < ----I want to use a compound OR, or compare multiple strings.
if(fruit != "orange"){ // <---------I want this nested if gone.
console.log(fruit + " is not apple or orange [two]");
}
}
});
const fruits = ["apple","orange","banana","cherry"];
fruits.forEach(function(fruit){
if(fruit != "apple"){
console.log(fruit + " is not apple");
}
});
fruits.forEach(function(fruit){ //<------- this is what I m having problems with
if(fruit != "apple" || fruit != "orange"){
console.log(fruit + " is not apple or orange [one]");
}
});
fruits.forEach(function(fruit){
if(fruit != "apple"){
if(fruit != "orange"){
console.log(fruit + " is not apple or orange [two]");
}
}
});