ES6 Set (most commonly used in ES6)

let,2,1,3 arr = [1] arr = [... new Set (arr)] / / [1, 2, 3]Copy the code

2, use for to nest for, and then splice (ES5 most commonly used)

let arr = [1, 3, 2, 4, 5, 3, 2, 1, 4, 6, 7, 7, 6, 6]
function deWeight(arr){            
        for(var i=0; i<arr.length; i++){
            for(var j=i+1; j<arr.length; j++){
                if(arr[I]==arr[j]){// if arr[I]==arr[j]); j--; }}}return arr;
}Copy the code

3. Use indexOf to remove weight

let arr = [1, 3, 2, 4, 5, 3, 2, 1, 4, 6, 7, 7, 6, 6]
let arr1 = []
for(var i=0; i<arr.length; i++){if(arr1.indexOf(arr[i]) === -1){
        arr1.push(arr[i])
    }
}
return arr1Copy the code

Sort ()

let arr = [1, 3, 2, 4, 5, 3, 2, 1, 4, 6, 7, 7, 6, 6]
let arr1 = []
arr = arr.sort()
for(var i=0; i<arr.length; i++){if(arr[i] ! == arr[i-1]){ arr1.push(arr[i]) } }return arr1Copy the code

5. Use includes

let arr = [1, 3, 2, 4, 5, 3, 2, 1, 4, 6, 7, 7, 6, 6]
let arr1 = []
arr = arr.sort()
for(var i=0; i<arr.length; i++){if(! Arr1.push (arr[I])}} Arr1.push (arr[I])}}return arr1Copy the code

6. Use filter

let arr = [1, 3, 2, 4, 5, 3, 2, 1, 4, 6, 7, 7, 6, 6]
arr.filter((item,index,arr)=>{
    return arr.indexof(item,0) === index
})Copy the code