Skip to content
Advertisement

How to replace switch with Object literals

When i rewriting my old code, i had a problem i don’t know to to optimize this code in past i use switch,but now i know about Object literals, my code:

JavaScript

How i can replace him with object literals?

Advertisement

Answer

You can write the cases as object literals and iterate over them:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement