I won't say much nonsense, the specific method is as follows:
Method 1: Return to the new array and each subtype of the bit has not changed.
function outRepeat(a){ var hash=[],arr=[]; for (var i = 0; i < a.length; i++) { hash[a[i]]!=null; if(!hash[a[i]]){ arr.push(a[i]); hash[a[i]]=true; } } console.log(arr); } outRepeat([2,4,4,5,"a","a"]);//[2, 4, 5, "a"]Method 2: Similar to Method 1, but this Agriculture thinks Method 1 is easier to understand
function outRepeat(a){ var hash=[],arr=[]; for (var i = 0,elem;(elem=a[i])!=null; i++) { if(!hash[elem]){ arr.push(elem); hash[elem]=true; } } console.log(arr); } outRepeat([2,4,4,5,"a","a"]);//[2, 4, 5, "a"]Method 3: It is easier to understand than the first two, but the number type of each bit of the returned new array has become a string type! ! Must be dealt with at critical moments
function outRepeat(a){ var hash=[],arr=[]; for (var i = 0; i < a.length; i++) { hash[a[i]]=null; } for(var key in hash){ arr.push(key); } console.log(arr); } outRepeat([2,4,4,5,"a","a"]);//["2", "4", "5", "a"]The above are three ways to remove duplications in JavaScript that the editor introduced to you. I hope it will be helpful to you!