I'm checking a variable, say foo
, for equality to a number of values. For example,
if( foo == 1 || foo == 3 || foo == 12 ) {
// ...
}
The point is that it is rather much code for such a trivial task. I came up with the following:
if( foo in {1: 1, 3: 1, 12: 1} ) {
// ...
}
but also this does not completely appeal to me, because I have to give redundant values to the items in the object.
Does anyone know a decent way of doing an equality check against multiple values?