Remove duplicates from an array

A function that removes duplicates in an array.

by Korah Babu Varghese

HTML

<a href="http://stackoverflow.com/questions/12551635/jquery-remove-duplicates-from-an-array-of-strings/12551709#12551709">Stackoverflow: remove duplicates from an array of strings</a>

JavaScript

function unique(list) {
    var result = [];
    $.each(list, function(i, e) {
        if ($.inArray(e, result) == -1) result.push(e);
    });
    return result;
}

var thelist = ["ball_1", "ball_13", "ball_23", "ball_1"];
document.write(unique(thelist));