I have 2 arrays, and I wanted to find if there were some items that overlapped! This is how I did it:
var Array1 = ["cat", "dog", "fish"]
var Array2 = ["apple", "cat", "poop"]
var list = []
Array1.some(item => {
if (Array2.includes(item)) {
list.push(item);
}
})
console.log(list) // ["cat"]
or
var doesItExist = (arrayA, arrayB) => {
return arrayA.some(r=> arrayB.includes(r))
}
doesItExist(Array1, Array2) // true
Leave a Reply