JS: How to remove duplicate items from an Array?
JS: How to remove duplicate items from an Array?
I guess there will be a simple way ...
JS: How to remove duplicate items from an Array?
I guess there will be a simple way ...
Hey!
Maybe something like this:
Array.prototype.unique = function (){
var r = new Array();
o:for(var i = 0, n = this.length; i < n; i++){
for(var x = 0, y = r.length; x < y; x++){
if(r==this) continue o;}
r[r.length] = this;}
return r;
}
Usage:
var myArray = ["a","b","c","c","a","d","b","b"];
alert(myArray.unique());
Hope that helps.
--
tomaxxi
http://indisnip.wordpress.com/
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.