编辑代码


// 偷懒方法
// function unique () {
//     let s = new Set(array);
//     return [...s]
// }

// 正经方法
function unique (arr) {
    let res = [];
    for(let i = 0; i < arr.length; ++i){
        if(res.indexOf(arr[i]) == -1){
            res.push(arr[i])
        }
    }
    return res
}

var array = [1, 1, '1', '1'];


console.log(unique(array))