JSFiddle - React, Tailwind, and code Playground

by Shef

HTML

<select id="my_select">
    <option value="1">First</option>
    <option value="2">Second</option>
    <option value="3">Third</option>
</select>

JavaScript

var my_value = 2;
$('#my_select option').each(function(){
    var $this = $(this); // cache the this jQuery object to avoid overhead

    if ($this.val() == my_value) { // if this option's value is equal to our value
        $this.prop('selected', true); // select this option
        return false; // break the loop, no need to look further
    }
});