数组去重
const arr = [1,2,1,2,3,4,1,5,1,2,6] //方法一 const arr1 = [...new Set(arr)] //方法二 const arr2 = Array.from(new Set(arr)) //方法三 function noDup1(arr){ let res = [] for(var i=0;i<arr.length;i++){ if(!res.includes(arr[i])){ res.push(arr[i]) } } return res } //方法四 function noDup2(arr){ arr = arr.sort() let i = 0 while(i<arr.length-1){ if(arr[i]===arr[i+1]){ arr.splice(i,1) }else{ i++ } } return arr }