vue 两个数组判断是否有重复

vue 两个数组判断是否有重复

vue 两个数组判断是否有重复,有几种判断方式?
let arr1 = ['runoob', 'google']
let arr2 = ['jingdong', 'google', 'taobao']


回答:

let arr1 = ['runoob', 'google']

let arr2 = ['jingdong', 'google', 'taobao']

const newArr = [...arr1, ...arr2]

const uniqArr = [...new Set(newArr)]

if(newArr.length !== uniqArr.length) // 有重复


回答:

随便写两种

let arr1 = ['runoob', 'google']

let arr2 = ['jingdong', 'google', 'taobao']

//

console.log(arr1.some(r => arr2.includes(r)))

//

console.log(!arr1.every(r => !arr2.includes(r)))

//

console.log(arr1.filter(r => arr2.includes(r)).length)

以上是 vue 两个数组判断是否有重复 的全部内容, 来源链接: utcz.com/p/937060.html

回到顶部