<script language= "JavaScript" > <!--var arrdata=new Array (); for (var i=0 i<1000; i++) {Arrdata[arrdata.length] = String.fromCharCode (Math.floor (Math.random () *26) +97);
document.write (arrdata+ "<br/>"); Method one, normal traversal function Myarray_unique (myarray) {//var myarray=new Array ("A", "a", "C", "A", "C", "D", "E", "F", "F", "G", "H", "G"
"," H "," K ");
var Haha=myarray; for (Var i=0;i<myarray.length;i++) {for (Var j=0;j<myarray.length;j++) {Temp=myarray[i]; if ((I+j+1) < MYARRAY.LENGTH&&TEMP==MYARRAY[I+J+1]///If the current element is equal to the latter element Haha.splice (i+j+1,1);
Then remove the next element}} return haha; }//Method two function Getunique (Somearray) {temparray=somearray.slice (0);//copy array to temporary array for (Var i=0;i<temparray.length;i+
+) {for (Var j=i+1;j<temparray.length;) {if (Temparray[j]==temparray[i])//The following elements are deleted and counted if they are the same as they are to be compared;//delete, the following elements are automatically advanced, so the pointer J does not move {temparray.splice (j,1);} else {j+
+;
}//Is different, then the pointer moves} return temparray; }//Method three regular expressions--applicable to character array function getUnique2 (A) {var str = "\x0f" + a.join ("\x0f");
while (/(\w+) [^\1]*\1/.test (str)) str = str.replace ("\x0f" + regexp.$1, "");
return Str.substr (1). Split ("\x0f");
}//Method four-associative structure Array.prototype.unique = Array_unique; function Array_unique () {var o = new Object (); for (var i=0,j=0; i<this.length; i++) {if (typeof o[this[i]] = ' undef
Ined ') {O[this[i]] = j + +;}}
this.length = 0;
for (var key in O) {This[o[key]] = key;
var d = new Date (). GetTime ();
document.write (Myarray_unique (arrdata));
D = new Date (). GetTime ()-D; document.write ("<br/>2000 element method one algorithm meter time consuming" + D + "millisecond!<br/><br/>");
About 370ms~390ms var d = new Date (). GetTime ();
document.write (Getunique (arrdata));
D = new Date (). GetTime ()-D; document.write ("<br/>2000 element method two algorithm meter time consuming" + D + "millisecond!<br/><br/>");
About 360ms~380ms var d = new Date (). GetTime ();
document.write (GetUnique2 (arrdata));
D = new Date (). GetTime ()-D; document.write ("<br/>2000 element Regular expression method three algorithm meter time consuming" + D + "millisecond!<br/><br/>");/About 80ms var d = new Date(). GetTime ();
document.write (Arrdata.unique ());
D = new Date (). GetTime ()-D; document.write ("<br/>2000 Element association structure method four algorithm meter time consuming" + D + "millisecond!<br/><br/>");/About 0ms~10ms//--> T>