var arr=[1,1,2,2,3,5,2];function uniqueArr(arr){ var data=[]; for(var i=0;i<arr.length;i++){ if(data.indexOf(arr[i])<0){ data.push(arr[i]); } } return data;}console.log(uniqueArr(arr));var arr1=[1,2,2,5,5,4,5,6,3,36,52];function uniquearr(arr){ var data=arr.sort(); var undata=[]; for(var i=0;i<arr.length;i++){ if(arr[i]!==arr[i+1]){ undata.push(arr[i]); } } return undata;}console.log(uniquearr(arr1));
时间: 2024-10-29 08:23:01