JS to clear the string array, the implementation method of repeating elements
<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 1, ordinary 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 next element haha.splice(i+j+1,1); //Then remove the next element}} return haha;} //Method two function getUnique(someArray){tempArray=someArray.slice(0);//Copy the array to the temporary array for(var i=0;i<tempArray.length;i++){for(var j=i+1;j<tempArray.length;){if(tempArray[j]==tempArray[i])//If the following elements are the same as those to be compared, they will be deleted and counted;//After deletion, the subsequent elements will be automatically advanced, so the pointer j does not move {tempArray.splice(j,1);}else{j++;}//Different, 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 Structures 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]] == 'undefined'){o[this[i]] = j++;}}this.length = 0;for (var key in o){this[o[key]] = key;}return this;} var d = new Date().getTime();document.write(myArray_Unique(arrData));d = new Date().getTime()-d;document.write("<br/>2000 element method one algorithm takes "+ d +" milliseconds!<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 counting takes "+ d +" milliseconds!<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 counting takes "+ d +" milliseconds!<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 Algorithms Calculation Time Takes "+ d +" milliseconds!<br /><br />");//About 0ms~10ms//--></script>The above article JS clears the implementation method of repeating elements in the string array is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.