1.使用new set()
const arr = [1,2,5,4,2,4,5,7,6,5,4];
const newArr = [...new set(arr)]
console.log(newArr ); // [1,2,5,4,7,6]
2.使用includes()方法
const arr = [1,2,5,4,2,4,5,7,6,5,4];
const newArr = [];
arr.forEach((ele, i) => {
if (!newArr .includes(ele)){
newArr.push(ele)
}
})
console.log(newArr ); // [1,2,5,4,7,6]