What's the best beautiful way to present your data, using multiple values for efficient comparison?
P粉384366923
2023-08-15 17:03:59
<p>What is the most beautiful way to compare a value with multiple options? </p>
<p>I know there are many ways to do this, but I'm looking for the neatest way. </p>
<p>I ask this question because I hope it is possible to do this (obviously not when you see it): </p>
<pre class="brush:php;toolbar:false;">if (foobar == (foo||bar) ) {
//do something
}</pre>
<p><br /></p>
My previous approach was to put these multiple values into an array, as follows:
Then use the indexOf() method:
If you want to be more beautiful:
For older browsers:
( https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/IndexOf )
Don't try to be too cunning, especially if it affects performance unnecessarily. If you really have a lot of comparisons to do, just format it nicely.