let arr = [1,2,3,4,3,2,3,5];
let unique = (arr)=>{
// 第一层 for 循环 数组的前一项
for(var i=0; i<arr.length; i++){
// 第二层 for 循环 数组后一项
for(var j=i+1; j<arr.length; j++){if(arr[i] === arr[j]){arr.splice(j,1);// 删除反复元素
j--;// 修改下标
}
}
}
return arr;
}
unique(arr);
console.log(arr);
let arr = [1,3,4,5,3,4,5,32,4];
let unique = (arr)=>{let newArr = [];// 新数组,用来接管不反复的元素
for(var i=0; i<arr.length; i++){if(newArr.indexOf(arr[i])===-1){newArr.push(arr[i]);
}
}
rerurn newArr;
}
console.log(unique(arr));
let arr = [1,3,5,3,5]
let unique = (arr)=>{let newArr = [];// 新数组,用来接管不反复的数组
for(var i=0; i<arr.length; i++){if(! newArr.includes(arr[i])){newArr.push(arr[i]);
}
}
return newArr;
}
console.log(unique(arr));
let arr = [3,43,3,2,5,4]
let set = new Set();
let [...a] = set;
console.log(a);