I have two arrays, array1 and array2, both containing elements of various types (strings, numbers, etc.). I want to find the intersection of these two arrays, i.e., the elements that are common to both arrays. What would be the most efficient way to achieve this using JavaScript? I’m open to any built-in methods or efficient algorithms.
const array1 = [1, 2, 3, 4, 5];
const array2 = [3, 4, 5, 6, 7];
console.log(intersection); // Should output [3, 4, 5]