After trying many methods and searching on Google, I have come to a dead end and decided to ask here for help.
My question pertains to displaying data in a select option dropdown menu using JSON array list.
Below is the code snippet:
<select name="" id="state_list">
<option>Select State</option>
</select>
<script>
var url = "#";
function getData() {
fetch(url)
.then((data) => {
return data.json();
})
.then((covidData) => {
var dropdown = document.getElementById("state_list");
var stateList = covidData.data.regional;
for (i = 0; i < stateList.lenght; i++) {
dropdown[dropdown.lenght] = new Option(stateList[i],stateList[i]);
}
})
</script>