The following code works fine:
var styles = []
if (state == 's1') {
styles = ['inline-block', 'none', 'none']
} else if (state == 's2') {
styles = ['none', 'inline-block', 'none']
} else if (state == 's3') {
styles = ['none', 'none', 'inline-block']
}
However in some languages we can make this more concise. I would like to do something along the following lines:
var styles =
if (state == 's1') {
['inline-block', 'none', 'none']
} else if (state == 's2') {
['none', 'inline-block', 'none']
} else if (state == 's3') {
['none', 'none', 'inline-block']
}
Is there such a conditional assignment - or even better some kind of match/case - in javascript?
Update Lots of good answers - thanks! Chose one seems closest to my original intent. But learnt a variety of aspects of javascript across many of them.