A map object is often an elegant alternative to switch statements and...


A map object is often an elegant alternative to switch statements and if/else statements.

A map object maps keys to values. The map's values can be strings, numbers, or even functions.

Here's an example of using a map to replace a switch:

Here's a codesandbox that shows the 2 approaches in action:

https://codesandbox.io/s/trusting-bartik-sjoi2f?file=/src/index.ts

View original on X