Intersection Array

Finds the common elements between two arrays.

Contributed by @itsbrunodev

javascript
function intersection(array1, array2) {
  return array1.filter((item) => array2.includes(item));
}
javascript
const array1 = [1, 2, 3];
const array2 = [2, 3, 4];
intersection(array1, array2); // [2, 3]

Keywords

array