Skip to content

Instantly share code, notes, and snippets.

@masautt
Created September 6, 2019 18:47
Show Gist options
  • Save masautt/c64cebd8b3d4503d6a65cf2dce6370a3 to your computer and use it in GitHub Desktop.
Save masautt/c64cebd8b3d4503d6a65cf2dce6370a3 to your computer and use it in GitHub Desktop.
How to find the intersection of 2 arrays in JavaScript?
function findIntersection(arr1, arr2) {
return arr1.filter(value => arr2.includes(value))
}
console.log(findIntersection(["M","A", "R", "E", "K"], ["M","A", "S", "A", "T", "T"])) // --> [ 'M', 'A' ]
// https://stackoverflow.com/questions/1885557/simplest-code-for-array-intersection-in-javascript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment