标签:set i++ obj UNC style span prot color this
1 // js数组去重 2 Array.prototype.fun1 = function(){ 3 var arr = this, 4 result = [], 5 i, 6 len = arr.length; 7 for(i = 0;i<len;i++){ 8 if(!(arr[i] in result)){ 9 result.push(arr[i]); 10 } 11 } 12 return result; 13 }; 14 Array.prototype.fun2 = function(){ 15 var arr = this, 16 i, 17 j, 18 len = arr.length; 19 for(i = 0;i<len;i++){ 20 for(j = i + 1;j<len;j++){ 21 if(arr[i] === arr[j]){ 22 arr.splice(j, 1); 23 len --; 24 j --; 25 } 26 } 27 } 28 return arr; 29 }; 30 Array.prototype.fun3 = function(){ 31 var arr = this, 32 i, 33 obj = {}, 34 result = [], 35 len = arr.length; 36 for(i = 0;i<len;i++){ 37 if(!obj[arr[i]]){ 38 result.push(arr[i]); 39 obj[arr[i]] = 1; 40 } 41 } 42 return result; 43 }; 44 Array.prototype.fun4 = function(){ 45 //数组递归去重 46 }; 47 Array.prototype.fun5 = function(){ 48 // [...new Set()] 49 }; 50 Array.prototype.fun6 = function(){ 51 // map, filter 52 var arr = this, 53 obj = {}, 54 result = []; 55 result = arr.filter((v, k)=>{ 56 57 }); 58 return result; 59 // arr.map(function(v, k){ 60 // }); 61 // return arr; 62 }; 63 var arr1 = [1,2,3,2]; 64 arr1.fun1();
标签:set i++ obj UNC style span prot color this
原文地址:https://www.cnblogs.com/souleigh-hong/p/9055468.html