Created
October 16, 2020 21:27
-
-
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....
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
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