我如何用一个if
来实现这一目标?第if(fruit != "apple" || fruit != "orange"){
章没有达到预期的效果?
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]");
}
}
});