Sorry if it sounds like a stupid question
I have this following JavaScript object:
data = {
"Max" : 100
}
This same object can also have the following form:
data = {
"January": {"Max" : 100}
}
I want to use one same function to retrieve the value of Max if given the two forms
And it made me wonder if it is possible to write a conditional expressions directly in the [] when you write the values you want to retrieve? Is this following expression allowed in JavaScript? Something like this:
data[monthly ? 'month' : '']
Of course I tried it and it doesn't work. But is there another way to do such a thing in a line? monthly is a boolean