判断一个数组中是否有重复值

new Map() + filter方法
let myMap = new Map()
let arr = arrList.filter(item => {
  return !myMap.has(item) && myMap.set(item, 1)
})

//如果有重复值,过滤的数组长度则大于1,继而将Id设为true
if (arr.length > 1) {
 this.arrId = true
} else {
 this.arrId = false
 }
}

猜你喜欢

转载自blog.csdn.net/m0_65274248/article/details/126845943