使用es5
var arr=[1,2,3,4,5,6,3,4,1,2,3,5,"a","b","c","a"];
var new_arr=[];
var new_obj={};
for(var i=0;i<new_arr.length;i++){
if(!new_obj.arr[i]){
new_arr.push(arr[i])
new_obj.arr[i]=true;
} }
console.log(temp_arr) // [1, 2, 3, 4, 5, 6, "a", "b", "c"]
使用es6
var arr=[1,2,3,4,5,6,3,4,1,2,3,5,"a","b","c","a"];
var newarr=new Set(arr);
console.log(newarr) // [1, 2, 3, 4, 5, 6, "a", "b", "c"]
网友评论