1 //js array de-weight2ARRAY.PROTOTYPE.FUN1 =function(){3 vararr = This,4result = [],5 I,6Len =arr.length;7 for(i = 0;i<len;i++){8 if(! (Arr[i]inchresult)) {9 Result.push (Arr[i]);Ten } One } A returnresult; - }; -Array.prototype.fun2 =function(){ the vararr = This, - I, - J, -Len =arr.length; + for(i = 0;i<len;i++){ - for(j = i + 1;j<len;j++){ + if(Arr[i] = = =Arr[j]) { AArr.splice (J, 1); atLen--; -J--; - } - } - } - returnarr; in }; -ARRAY.PROTOTYPE.FUN3 =function(){ to vararr = This, + I, -obj = {}, theresult = [], *Len =arr.length; $ for(i = 0;i<len;i++){Panax Notoginseng if(!Obj[arr[i]]) { - Result.push (Arr[i]); theObj[arr[i]] = 1; + } A } the returnresult; + }; -Array.prototype.fun4 =function(){ $ //Array recursion weight $ }; -Array.prototype.fun5 =function(){ - //[.... New Set ()] the }; -Array.prototype.fun6 =function(){Wuyi //Map, Filter the vararr = This, -obj = {}, Wuresult = []; -result = Arr.filter ((V, k) = ={ About $ }); - returnresult; - //Arr.map (function (V, k) { - // }); A //return arr; + }; the varARR1 = [1,2,3,2]; -Arr1.fun1 ();
js Array de-weight (multiple methods)