Created
May 12, 2016 23:41
-
-
Save coopermaruyama/aa0c84e19ce8c6fb3a5d44bef547d44a to your computer and use it in GitHub Desktop.
ES6: Check if array contains an item in another array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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