So I have an array ["miranda","brad","johnny"]
and I want to check if in the array the values are either equal to miranda or to john or even brad to return true one time and not three times if one or more of the names are present and if not It displays an error if any other value are in this array. Now to make my example clearer here is a snippet that would represent what I'm thinking of:
let array = ["miranda","brad","johnny"]
for(var i = 0; i < array.length;i++){
if(array[i] == "brad" || array[i] == "miranda" || array[i] == "john"){
console.log("success")
} else{
console.log("fail");
break;
}
}
Now my goal here is to simplify and shorten this code to be left with a one line condition, I have already tried this technique (Check variable equality against a list of values) with if(["brad","miranda","john"].indexOf(array) > -1) { // .. }
but this does not solve my problem. Would you have any idea?
Thanks in advance.