You can stash your values inside an array and check whether the variable exists in the array by using [].indexOf
:
if([5, 6].indexOf(x) > -1) {
// ...
}
If -1
is returned then the variable doesn’t exist in the array.
More Related Contents:
- Sort array of objects by string property value
- Is there a standard function to check for null, undefined, or blank variables in JavaScript?
- Object comparison in JavaScript [duplicate]
- Sorting in JavaScript: Shouldn’t returning a boolean be enough for a comparison function?
- What’s the prettiest way to compare one value against multiple values? [duplicate]
- Comparing date part only without comparing time in JavaScript
- Switch statement for greater-than/less-than
- How do I check for null values in JavaScript?
- Comparing Arrays of Objects in JavaScript
- Why is string “11” less than string “3”? [duplicate]
- Why `null >= 0 && null
- Optimum way to compare strings in JavaScript? [duplicate]
- (…()) vs. (…)() in javascript closures [duplicate]
- Is it safe to assume strict comparison in a JavaScript switch statement?
- javascript surprising array comparison
- How to check identical array in most efficient way? [duplicate]
- Deep comparison of objects/arrays [duplicate]
- JavaScript performance difference between double equals (==) and triple equals (===)
- How to check if a variable is not null?
- How does (A == B == C) comparison work in JavaScript?
- Compare Strings Javascript Return %of Likely
- Javascript – deepEqual Comparison
- Why javascript treats 0 equal to empty string? [duplicate]
- JQuery string contains check [duplicate]
- Anagrams finder in javascript
- Wildcard string comparison in Javascript
- How do I chain three asynchronous calls using jQuery promises?
- How to access Session variables and set them in javascript?
- Javascript – telling setInterval to only fire x amount of times?
- React’s setState method with prevState argument