The shortest answer here is probably regex:
return /^[\/lL]$/.test(this.value);
(This checks for a single-char string where the char is one of /
, i
, or L
.)
More generally, your choices here are essentially:
An OR'd series of conditionals:
val === "/" || val === "i" || val === "L"
. This is clear, but redundant, and stops being legible after about three options. It's worth noting, however, that this is probably the fastest option - this might matter if you had to test 10k strings in quick succession.A regex check as above. This is likely the most concise code, and it's easy to add more characters or more complex patterns to the check, but it's less legible.
Array inclusion. This is easiest when you have access to modern array methods, e.g.
return chars.any(function(c) { return c === val; })
. This may be the best option if your list of search strings is determined at runtime, or simply if it's very long.