add option to datalist javascript code example
Example 1: create javascript array from datalist dynamically
var str='';
var month = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
for (var i=0; i < month.length;++i){
str += '<option value="'+month[i]+'" />';
}
Example 2: javascript array from datalist
var options = document.getElementById('estados').getElementsByTagName('option');
var optionVals = [], i = 0;
for (i; i < options.length; i += 1) {
optionVals.push(options[i].value);
}
console.log(optionVals);