JS 数组去重
1.for循环 + indexOf / includes
let arr = [1, 2, 1, 3, 2, 4, 3, 5, 4]
let newArr = []
for (let i = 0, l = arr.length; i < l; i++) {
if (newArr.indexOf(arr[i]) === -1) {
newArr.push(arr[i])
}
}
2.通过Set和拓展运算符 ...
let arr = [1, 2, 1, 3, 2, 4, 3, 5, 4]
let newArr = [...new Set(arr)]
console.log(newArr)
工作中如果有您解决不了的问题或者您花费2小时还没解决的问题,这里可以有偿帮您高效直接解决bug,wx号:18062748486,备注”bug解决“;