Skip to content

SWITCH ^v2.6.128

Execute different expressions based on the input value of an expression, useful when there are few possible values. Cleaner than long if chains.

js
SWITCH(expression, case_a, result_a, ...case_result_n, default)
SWITCH(expression, case_a, result_a, ...case_result_n, default)

Parameters

  • expression - Value to match to a case.
  • case_a - Value that will be compared against expression.
  • result_a - Value returned when the corresponding case matches the expression.
  • case_result_n - More case, result as required. (optional)
  • default - Default result if no matches are found.

Examples

js
SWITCH("Monday", "Monday", "Today is monday", "Tuesday", "Today is tuesday", "Today is not either monday or tuesday")
SWITCH("Monday", "Monday", "Today is monday", "Tuesday", "Today is tuesday", "Today is not either monday or tuesday")

Result: Today is monday

js
SWITCH(5, 1, 100, 2, 200, 300)
SWITCH(5, 1, 100, 2, 200, 300)

Result: 300