种数组去重比较简单的方案
作者:互联网
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]
标签:方案,arr,set,const,log,比较简单,newArr,ele,数组 来源: https://blog.csdn.net/w807139809/article/details/122104112