インデックスではなく、オプション要素にクラスを設定し、そのようにアドレス指定する方がよいでしょう。
<select id="my-select">
<option class="caramel">Twix</option>
<option>Mounds</option>
<option class="caramel">Milky Way</option>
<!-- ... -->
</select>
その後:
$("option.caramel", "#my-select").each(function () { this.selected = true });
編集:
しかし、本当にインデックスでそれを実行したい場合は、次のことができます。
function selectOptionsByIndex(select, indexes) {
var i = 0;
select.children().each(function (j) { if (indexes[i] == j) { ++i; this.selected = true } });
}
selectOptionsByIndex($("#my-select"), [ 1, 3, 4, 5, 9, 12 ]);
(これは、提供されたインデックスの昇順のリストによって異なります。)