Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
169
rated 0 times [  174] [ 5]  / answers: 1 / hits: 192394  / 13 Years ago, thu, february 2, 2012, 12:00:00

Whats the prettiest way to compare one value against multiples options?



I know there are loads of ways of doing this, but I'm looking for the neatest.



i ask because i'd hoped this was workable (it isn't, quite obviously when you look at it):



if (foobar == (foo||bar) ) {
//do something
}

More From » comparison

 Answers
11

Don't try to be too sneaky, especially when it needlessly affects performance.
If you really have a whole heap of comparisons to do, just format it nicely.



if (foobar === foo ||
foobar === bar ||
foobar === baz ||
foobar === pew) {
//do something
}

[#87666] Wednesday, February 1, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
timothyc

Total Points: 233
Total Questions: 103
Total Answers: 103

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
;