{
let arr = [1, 2, 1, 1, 3, 4, 5, 5, 5, 6];
console.log([...new Set(arr)]);
} {
let arr = [1, 2, 1, 1, 3, 4, 5, 5, 5, 6];
let newArr = arr.filter((item, index) => {
return arr.indexOf(item) == index;
});
console.log(newArr);
} {
let arr = [1,2,1,1,3,4,5,5,5,6];
let newArr = [];
arr.forEach(item=>{
if(!newArr.includes(item)){
newArr.push(item);
}
})
console.log(newArr);
}
原文:https://www.cnblogs.com/jiaoyisen/p/14807235.html