Loop through all the options in select HTML using JS

In some cases you need to loop thru all options in the select HTML component. This code demonstrate how to do it:

 


var select = document.getElementById("Market");

for(i = 0; i < select.options.length; i++)
{
    //Display the option value
    console.log(select.options[i].value);

    //Display the option text
    console.log(select.options[i].text);
}