0

This is kinda hard to explain, but lets say I have a select input in my html with two options: optionA and optionB. In JS, i also have two objects. optionA & optionB. they would look like this:

var optionA = {
  content:"a"
}
var optionB = {
  content:"b"
}

Can I use the value of the HTML select to get .content of the corresponding variable?

I know the obvious solution would be if stetements:

if (select.value == "optionA") {
  var output = optionA.content
}

if (select.value == "optionB") {
  var output = optionB.content
}

but my project has heaps of these, and I just need a way to shortcut it. Is this possible in JS?

0 Answers0