1 Answer

0 votes
by

You can use indexOf to compare input with multiple values instead of checking each value as one condition.

// Verbose approach
if (
  input === "first" ||
  input === 1 ||
  input === "second" ||
  input === 2
) {
  someFunction();
}
// Shortcut
if (["first", 1, "second", 2].indexOf(input) !== -1) {
  someFunction();
}
...