Return to Snippet

Revision: 18362
at September 29, 2009 06:55 by svenito


Initial Code
Array.prototype.unique = function() {
    var newArray=new Array();
    label:for (var i=0; i < this.length; i++) {  
        for (var j=0; j < newArray.length; j++) {
            if (newArray[j] == this[i]) 
                continue label;
        }
        newArray[newArray.length] = this[i];
    }
    return newArray;
}

Initial URL

                                

Initial Description
Ensures all elements in an array are unique

newArray = myArray.unique();

Initial Title
Ensure all elements in array are unique

Initial Tags
array

Initial Language
JavaScript