Sometimes, we want to check variable equality against a list of values with JavaScript.
In this article, we’ll look at how to check variable equality against a list of values with JavaScript.
How to check variable equality against a list of values with JavaScript?
To check variable equality against a list of values with JavaScript, we can use the array includes
method.
For instance, we write
if ([1, 47, 28].includes(foo)) {
// ...
}
to call [1, 47, 28].includes
with foo
to check if foo
is one of 1, 47 or 28.
Conclusion
To check variable equality against a list of values with JavaScript, we can use the array includes
method.