Created
January 31, 2014 17:29
-
-
Save jdiamond/8737709 to your computer and use it in GitHub Desktop.
This file contains 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
var arr1 = [ { name: 'Nikki' }, { name: 'Jason' }, { name: 'Thanh' } ]; | |
var arr2 = [ { name: 'Nikki' }, { name: 'Thanh' } ]; | |
var index = {}; | |
arr1.forEach(function(item) { | |
index[item.name] = item; | |
}); | |
console.log(index); | |
var intersection = []; | |
arr2.forEach(function(item) { | |
if (item.name in index) { | |
intersection.push(item); | |
} | |
}); | |
console.log(intersection); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment