1javascript add option/element to select:
2const newOpt = document.getElementById('option-input');
3let mySelect = document.getElementById('mySelect'); //Object not array
4const opts = Object.values(mySelect.options);
5const option = document.createElement('option');
6optValues = opts.map(opt => opt.value.toLowerCase());
7//Validate if option exists
8if(optValues.indexOf(newOpt.value.toLowerCase()) !== -1){
9 newOpt.nextElementSibling.after("Category exists");
10 }else{
11 option.value = newOpt.value;
12 option.text = newOpt.value;
13 mySelect.add(option);
14 mySelect.value = option.value;
15 }