For example, I have 2 arrays:
arr1 = ["a","e","i","o","u"];
arr2 = ["h", "e", "l", "l", "o"];
I would like to find whether any of the elements in arr2 contain any of the elements that are already available in arr1.
For example, I have 2 arrays:
arr1 = ["a","e","i","o","u"];
arr2 = ["h", "e", "l", "l", "o"];
I would like to find whether any of the elements in arr2 contain any of the elements that are already available in arr1.
Use Array.some
to check whether one of the items in arr2
is included in arr1
:
arr1 = ["a", "e", "i", "o", "u"];
arr2 = ["h", "e", "l", "l", "o"];
const res = arr2.some(e => arr1.includes(e))
console.log(res)
Find the array with below filter function
let array1 = ["a","e","i","o","u"];
let array2 = ["h", "e", "l", "l", "o"];
const filteredArray = array1.filter(value => array2.includes(value));
filteredArray.length
will give you the answer
Try this.
arr1 = ["a","e","i","o","u"];
arr2 = ["h", "e", "l", "l", "o"];
let res = arr1.some(el1 => {
return arr2.some(el2 => el1 === el2);
});
console.log(res) // true