Skip to content

Instantly share code, notes, and snippets.

@CryceTruly
Last active March 9, 2021 15:15
Show Gist options
  • Save CryceTruly/824cd41234a494b63144d57a78f34287 to your computer and use it in GitHub Desktop.
Save CryceTruly/824cd41234a494b63144d57a78f34287 to your computer and use it in GitHub Desktop.
Here is how you can do it when the items in the arrays are objects.
The idea is to find the array of only the keys in an inner array using the map function
Then foreach of those check if they contain a spectific element key in the outer array.
const existsInBothArrays = array1.filter((element1) =>
array2.map((element2) => element2._searchKey).includes(element1._searchKey),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment