I have two arrays list1 and list2 which have objects with some properties; userId is the Id or unique property:
list1 = [
{ userId: 1234, userName: 'XYZ' },
{ userId: 1235, userName: 'ABC' },
{ userId: 1236, userName: 'IJKL' },
{ userId: 1237, userName: 'WXYZ' },
{ userId: 1238, userName: 'LMNO' }
]
list2 = [
{ userId: 1235, userName: 'ABC' },
{ userId: 1236, userName: 'IJKL' },
{ userId: 1252, userName: 'AAAA' }
]
I'm looking for an easy way to execute the following three operations:
list1 operation list2should return the intersection of elements:[ { userId: 1235, userName: 'ABC' }, { userId: 1236, userName: 'IJKL' } ]list1 operation list2should return the list of all elements fromlist1which don't occur inlist2:[ { userId: 1234, userName: 'XYZ' }, { userId: 1237, userName: 'WXYZ' }, { userId: 1238, userName: 'LMNO' } ]list2 operation list1should return the list of elements fromlist2which don't occur inlist1:[ { userId: 1252, userName: 'AAAA' } ]