I've the below HTML code, and need to update the "option" element dynamically, by a big list of elements coming back from the server
<select id='select'>
<option value = '0' selected></option>
</select>
So, I wrote the below JS code:
var select = e.querySelector('#select');
for(var k=0; k<5;k++){
var opt = document.createElement('option');
opt.value=data[k].value;
opt.text=data[k].text;
select.add(opt);
}
I do not need to use JQuery or any other plugin.
Is there a more neat and/or simpler way to do the same?
for(var k in data).for-inisn't for iterating arrays, more here.