Skip to content

Instantly share code, notes, and snippets.

@coopermaruyama
Created May 12, 2016 23:41
Show Gist options
  • Save coopermaruyama/aa0c84e19ce8c6fb3a5d44bef547d44a to your computer and use it in GitHub Desktop.
Save coopermaruyama/aa0c84e19ce8c6fb3a5d44bef547d44a to your computer and use it in GitHub Desktop.
ES6: Check if array contains an item in another array
const arr = [1,2,3];
const otherArr = [3,4,5];
arr.some(a => otherArr.some(b => a === b)); // => true
// using a collection and comparing with keys
const collection = [{a: 1}, {a: 2}, {a: 3}];
const collection2 = [{a: 3}, {a: 4}, {a: 5}];
collection.some(a => collection2.some(b => a.a === b.a)); // => true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment