Skip to content
Advertisement

How to shorten multiple if statements (not if else)

I have an array in which i want to conditionally push some values. Is there a cleaner way of doing this (code below)?

JavaScript

Advertisement

Answer

You can put the values x, y, z into an array and loop over the values with the index.

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