Referenced from: http://www.cnblogs.com/sosoft/archive/2013/12/08/3463830.html
The array type does not provide a way to repeat, and if you want to kill the repeating elements of the array, you have to do it yourself:
1functionUnique (arr) {2var result =[], isrepeated;3for (var i = 0, len = arr.length; i < Len; i++) {4 isrepeated =False;5for (var j = 0, len = result.length; J < Len; J + +) {6if (arr[i] = =Result[j]) {true;< Span style= "color: #008080;" > 8 break; 9 }10 }11 if (! isrepeated) {12 Result.push (Arr[i]); 13 }14 }15 return Result;
The general idea is to move the elements of the array to another array one by one, checking to see if the element is duplicated in the process of handling it, and throwing it away if any. As you can see from the nested loops, this method is extremely inefficient. We can use a Hashtable structure to record existing elements so that the inner loop can be avoided. Exactly, the implementation of Hashtable in JavaScript is extremely straightforward and is improved as follows:
function Unique (arr) { var result = [], hash = {}; For (null; i++if (! Truereturn result; http://www.cnblogs.com/sosoft/}
High efficiency remove duplicates in JS array