JavaScript: Removing duplicates from a select

From The Travis van der Font Wiki
Jump to: navigation, search
jQuery:
var optionValues = [];

$('#select_id option').each(function ()
{
    if ($.inArray(this.value, optionValues) >-1)
    {
        $(this).remove();
    }
    else
    {
        optionValues.push(this.value);
    }
});
(apply after the DOM is loaded)