The common methods are as follows:

function uniqueArr(arr) {
    return [...new Set(arr)]
}
Copy the code

Here we create an array of instances to test as follows:

let arr = [1.1."1"."1".true.true."true", {}, {},"{}".null.null.undefined.undefined]
Copy the code

function one

let uniqueOne = Array.from(new Set(arr))
console.log(uniqueOne)
Copy the code

function two

let uniqueTwo = arr= > {
    let map = new Map(a);// Or use an empty object let obj = {} to make use of object properties that cannot be repeated
    let brr = []
    arr.forEach( item= > {
        if(! map.has(item)) {// If it is an object, it can be judged! obj[item]
            map.set(item,true) // obj[item] =true
            brr.push(item)
        }
    })
    return brr
}
console.log(uniqueTwo(arr))
Copy the code

function three

let uniqueThree = arr= > {
    let brr = []
    arr.forEach(item= > {
        // Use indexOf to return whether the array contains a value
        if(brr.indexOf(item) === -1) brr.push(item)
        // Or use includes to return whether the array contains a value false or true if it does
        if(! brr.includes(item)) brr.push(item) })return brr
}
console.log(uniqueThree(arr))
Copy the code

function four

let uniqueFour = arr= > {                                         
     // Use filter to return the set that matches the criteria
    let brr = arr.filter((item,index) = > {
        return arr.indexOf(item) === index
    })
    return brr
}
console.log(uniqueFour(arr))
Copy the code