Skip to content

Instantly share code, notes, and snippets.

@jdiamond
Created January 31, 2014 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdiamond/8737709 to your computer and use it in GitHub Desktop.
Save jdiamond/8737709 to your computer and use it in GitHub Desktop.
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