I have a list of items:
<select id ="listSelector">
<option value="books">Books</option>
<option value="countries">Countries</option>
<option value="states">States</option>
<option value="presidents">Presidents</option>
</select>
Which correspond to arrays of items:
var books = ['genesis', 'exodus', 'leviticus', 'numbers'];
var countries = ['Akrotiri','Albania','Algeria','American'];
var states = ['Alabama','Alaska','Arizona','Arkansas'];
var presidents = ['Washington','Adams','Jefferson','Madison'];
I want to be able to select an item from the list and use the value of the item to select the correct array.
var listSelector = document.getElementById('listSelector');
var selectedList = listSelector.options[listSelector.selectedIndex].value;
console.log('selected', selectedList[0]);
// returns first letter of the value of the list that was selected
// instead of the first item in the array.
// Ex. If I selected the Books option, the value would be 'books'
// and I want to access the books array.
var infos = { "books": [...], "countries": [...], ... }; infos[selectedValue]