怎么去掉javascript 的Array的重复项
//完美去除法:
var arr=[1,3,2,2,11,4]; var arr1=[]; var arr2=arr.sort(function(a,b){ return a-b; }); //把数组进行排序 var num=1; for (var i=0;i<arr2.length;i++){ if(arr2[i]!==arr2[(num++)]){ arr1.push(arr[i]); } } console.log(arr1);
//完美去除法:
var arr=[1,3,2,2,11,4]; var arr1=[]; var arr2=arr.sort(function(a,b){ return a-b; }); //把数组进行排序 var num=1; for (var i=0;i<arr2.length;i++){ if(arr2[i]!==arr2[(num++)]){ arr1.push(arr[i]); } } console.log(arr1);