Find common items from two arrays in JavaScript

Consider you have two arrays and you want to find the common items in both the array.

In mathematical terms, it is called as intersection. Lets find the intersection of two different simple arrays,

const blogAuthors = ['Param', 'Joshua', 'Fernando', 'Moises'];
const newsletterAuthors = ['Param', 'Joshua', 'Afrin'];

Let's find common authors in those two arrays,

// common authors from blog and newsletter authors
const commonAuthors = newsletterAuthors.filter(author =>

console.log(commonAuthors); // ['Param', 'Joshua']

We filtered the newsletterAuthors array by checking whether the author exists in the blogAuthors list.

See it in action here,