Javascript - Determine if String Is In List
- by Emtucifor
In SQL we can see if a string is in a list like so:
Column IN ('a', 'b', 'c')
What's a good way to do this in javascript? I realize one can use the switch function:
var str = 'a'
var flag = false;
switch (str) {
case 'a':
case 'b':
case 'c':
flag = true;
default:
}
if (thisthing || thatthing || flag === true) {
// do something
}
But this is a horrible mess. It's also clunky to do this:
if (thisthing || thatthing || str === 'a' || str === 'b' || str = 'c') {
// do something
}
And I'm not sure about the performance or clarity of this:
if (thisthing || thatthing || {a:1, b:1, c:1}[str]) {
// do something
}
Any ideas?