An array to repeat is a common requirement, and we temporarily consider the same type of array to repeat. The main reason is to clear the thinking and consider performance.
The For loop deletes the following duplicate
var uniquefor = function (arr) {
for (var i = 0; i < arr.length-1; i++) {
var item = Arr[i];
for (var j = i+1 J < Arr.length; J + +) {
item = = = Arr[j] && (Arr.splice (J, 1), j--);
}
};
return arr;
};
Determining Object Properties
var uniqueobject = function (arr) {
var V, r = [], o = {};
for (var i = 0; (v = arr[i])!== undefined; i++) {
!O[V] && (R.push (v), o[v] = true);
}
return R;
};
Array Filter Duplicates Filter
var uniquefilter = function (arr) {
Return Arr.filter (Function (Elem, POS, self) {
Returns true if there are no duplicates
Return Self.indexof (Elem, pos + 1) = =-1;
});
};
Compare execution efficiency
Figure 1 Chrome browser
Figure 2 Firefox browser