种数组去重比较简单的方案

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]
上一篇:CF1408D Searchlights


下一篇:MySQL命令学习笔记