how to append options to datalist in javascript code example
Example 1: create javascript array from datalist dynamically
<input name="month" list="months" >
<datalist id="months" >
</datalist>
<script language="javascript">
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]+'" />';
}
var my_list=document.getElementById("months");
my_list.innerHTML = str;
</script>
Example 2: how to fill html datalist with array values in javascript
let str='';
let htmlstring = Names.forEach((name) => {
str += '<option value="' + name + '" />';
});