Is there a way to test whether or not an array contains at least one element from another array?
let array1 = [`a`, `b`, `c`, `d`, `e`];
let array2 = [`c`];
Basically is there a way to determine if array2 has any of the elements from array1 in a single step. I realize I could check to see if array2 has a or b or c or d or e, but I'm curious if there is a method that helps me.
includes() only allows me to check for one value. some() would allow me to test if c is included in array1 but not test if any of the five elements from array1 are part of the array2.
Is there some way of using reduce() or filter()?
You could take Array#some with a Set.
const
array1 = ['a', 'b', 'c', 'd', 'e'],
array2 = ['c'],
hasValue = array2.some(Set.prototype.has, new Set(array1));
console.log(hasValue);