Skip to content

Instantly share code, notes, and snippets.

@kabeer11000
Created October 16, 2020 21:27
Show Gist options
  • Save kabeer11000/a098a37995a733b9118cf91dcd4c11f2 to your computer and use it in GitHub Desktop.
Save kabeer11000/a098a37995a733b9118cf91dcd4c11f2 to your computer and use it in GitHub Desktop.
Easy with new ES6 Syntax Second and Third way are more performant i guess....
const a = [{
'id': '1',
'name': 'a1'
}, {
'id': '2',
'name': 'a2'
}, {
'id': '3',
'name': 'a3'
}];
const b = [{
'id': '2',
'name': 'a2'
}];
a.filter(i => !b.filter(y => y.id === i.id).length); // One Way
a.filter(i => !b.find(f => f.id === i.id)); // Second Way
a.filter(i => b.findIndex(f => f.id === i.id)) // Third Way
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment