Return to Snippet

Revision: 25839
at April 11, 2010 23:10 by djmicahelb


Initial Code
Array.prototype.myUnique = function(){
	var r = new Array();
	o:for(var i = 0; i < this.length; i++) {
		for(var x = 0; x < r.length; x++) {
			if(r[x]==this[i]) {
				continue o;	
			}
		}
		r[r.length] = this[i];
	}
	return r;
};

//usage

yourArray = yourArray.myUnique();

Initial URL

                                

Initial Description
Use this to step through an Array and keep only values the first instance of any values, removing all subsequent duplicates.

Initial Title
Javascript remove duplicates from Array

Initial Tags

                                

Initial Language
JavaScript