js数组去重
var arr=[1,3,6,3,5,7,7,3,6,8,1,2,4,3,7,8,6,4,3,2,2]; var arr1=[]; for(var i=0;i<arr.length;i++){ var item=arr[i]; var bool=true; for(var j=0;j<arr1.length;j++){ if(arr1[j]===item){ bool=false; break; } } if(bool){ arr1.push(item); } } console.log(arr); console.log(arr1);
var arr=[1,4,3,2,3,4,6,7,4,2,1,3,5,3,2,4,6,0,9]; for(var i=0;i<arr.length;i++){ var item=arr[i]; for(var j=i+1;j<arr.length;j++){ if(item===arr[j]){ arr.splice(j,1); j--; } } } console.log(arr);