0
Compare a variable with every member of an array?
So if I want to compare a varibale with an array if(var = arr[0] || var = arr[1] || var = arr[2] ...) is there a possibility to do it easier, faster, with less writing? something like if(var = arr[all]) or for(int i = 0; i < arr.length; i++) if(var == arr[i]) //do stuff ?
2 odpowiedzi
+ 10
for (var i=0; i< arr.length; i++) {
if (var == arr[i]) {
// Code here
}
}
+ 1
I figured it out by now
seems like the one in my example ..
maybe I shouldn't hesitate and ask everything before experementing
thank you for your contribution