I have a string and an array. Let's say there are 5 elements in array now i want to perform a function that if that string is not equal to any value of array then perform function. I simply used a loop to iterate the array for example: I have array
var cars = ["Saab", "Volvo", "BMW","Audi"];
String output ="Audi";
for(let i=0;i<cars.length;i++)
{
if(output != cars[i])
{
// run a code
}
}
But the problem comes for example the element at index 0 in array is not equal to the string so the condition in loop runs. I want to check whole array in single loop. In simple words, I want to run a function if the value of string does not equal any value of string in javascript