Finds the common elements between two arrays.
Contributed by @itsbrunodev
function intersection(array1, array2) {
return array1.filter((item) => array2.includes(item));
}
const array1 = [1, 2, 3];
const array2 = [2, 3, 4];
intersection(array1, array2); // [2, 3]