小唯快跑啊
var arr = [1, 'a', '1', 2, '2', 'b', 'b'];
let resultarr = [...new Set(arr)];
console.log(resultarr);//[1, "a", "1", 2, "2", "b"]如果不去重对象的可以用下面的var arr = [1, 'a', '1', 2, '2', 'b', 'b', null, null, , ,'null'];var obj = {};var result = [];for (var i = 0; i < arr.length; i++) { var key = typeof arr[i]+arr[i]; if(!obj[key]){
obj[key] = true;
result.push(arr[i])
}
}console.log(result);//或者不用多余的数组存储for (var i = 0; i < arr.length; i++) { var key = typeof arr[i]+arr[i]; if(!obj.hasOwnProperty(key)){
obj[key] = arr[i];
}
}console.log(Object.values(obj));//es5 for in遍历