JSFiddle - React, Tailwind, and code Playground
by thomas_peklak
HTML
<select id="mySelect" multiple="multiple">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3">Third</option>
<option value="4">Fourth</option>
</select>
JavaScript
var options = {};
$('#mySelect option').each(function(){
options[$(this).text()] = $(this).val();
});
console.log(options);
//or the other way round
var options2 = {};
$('#mySelect option').each(function(){
options2[$(this).val()] = $(this).text();
});
console.log(options2);