I have a menu. Given a given value, I would like to return the text. For instance, 0 would return “zero”, 1 would return “one”, etc. Note that I do not care which option is currently selected nor do I want to auto-select the menu, but just want to use the select menu as a primitive database. Can this be done easily with JavaScript or jQuery without iterating over each option?
<select>
<option value="0">zero</option>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
</select>
Thanks
Instead of using the
selectas a database (requiring an expensive operation for simple lookups), create a data set from it once, then use that…Or if the
optionvalues aren’t sequential0based indices, then use an object…