Voici un simple algorithme, et apparemment rapide, trouvé sur http://www.shamasis.net/2009/09/fast-algorithm-to-find-unique-items-in-javascript-array/ et que j’ai raccourci légèrement :
1 2 3 4 5 6 7 8 | Array.prototype.unique=[].unique|| function (){ var o={},i,l= this .length,r=[]; for (i=0;i<l;i++)o[ this [i]]= this [i]; for (i in o)r.push(o[i]); return r} // or, if you don't want to override the Array prototype: var ArrayUnique = function (arr){ var o={},i,l=arr.length,r=[]; for (i=0;i<l;i++)o[arr[i]]=arr[i]; for (i in o)r.push(o[i]); return r} // exemple var tab=[1, 5, 2, 4, 1, 5, 4, 1, 5, 6, 8 ]; var tabUniq=tab.unique(); // [1, 5, 2, 4, 6, 8] |