Sorry about my terminology, this pattern probably exist in other languages and I just don't know the name of it.
Simply, if I want to create an if statement where a value must match 1 other value in a list.
const val = "big";
if (val === "tiny" || val === "small" || val === "medium" || val === "large") {
// valid size
}
There are a bunch of SO articles out there asking what the best solution is and there are many variations. But could something be built into the language eventually? I'm sure it has been discussed before, what were the outcomes?
Ideally, it could look something like ...
const val = "big";
if (val ==~ "tiny" || "small" || "medium" || "large") {
// valid size
}
There are as many variations of the question as there are solutions. The outcomes of prior syntax proposals were that the existing solutions are good enough - and not worth the hassle of introducing new syntax. With ES6 specifically, you can write
if (["tiny", "small", "medium", "large"].includes(val))
or
if (new Set(["tiny", "small", "medium", "large"]).has(val))
and the most concise solution for strings is probably