Any idea how to remove duplicates?
Im sure its easy, but kind find a reference anywhere.
Mark
Remove duplicates from JavaScript array
Moderator: General Moderators
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Maybe there's a method but I'm not aware of it so perhaps something like this. It'll support associative and numbered indexes.
Although that was a bit rushed at work and for large arrays it might be a bit slow with those nested loops 
Code: Select all
var sillyArray = new Array(
'mr bump',
'mr grumpy',
'mr nosey',
'mr silly',
'mr funny',
'mr nosey' //duplicate!
);
function arrayUnique(a) {
y = new Array();
for (x in a) {
d = false; //d; a.k.a. duplicate
for (i in y) {
if (yїi] == aїx]) d = true;
}
if (!d) yїx] = aїx];
}
return y;
}