Remove duplicates from JavaScript array
Posted: Thu Jun 02, 2005 5:52 am
Any idea how to remove duplicates?
Im sure its easy, but kind find a reference anywhere.
Mark
Im sure its easy, but kind find a reference anywhere.
Mark
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
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;
}