Possible Duplicate:
javascript function inArray
In Python, I can do multi-equivalence testing by doing:
if x in [1, 2, 3, 4, 5]:
do something
How would I do this in javascript?. Currently I’m doing:
if (x == 1 || x == 2 || x == 3 || x == 4 || x == 5) {
do something
}
In JavaScript there is
indexOfmethod:Note, that this method is not supported by some old browsers, so it is recommended to use shim.
By the way,
inoperator exists in JavaScript, and is primarily used for checking property existence in objects, for example: