JSFiddle - React, Tailwind, and code Playground
by brigand
HTML
<select name="" id="myselect" multiple>
<option value="foo">foo</option>
<option value="bar">bar</option>
<option value="baz">baz</option>
</select>
<pre id="out"></pre>
JavaScript
Array.from(myselect.children, (x, i) => {
if (i !== 1) {
x.selected = true;
}
});
out.textContent = Array.from(myselect.selectedOptions, x => x.value).join(', ');