I have two lists of objects, each containing two fields:
let users1 = [{ name: 'barney', uuid: 'uuid3'},
{ name: 'barney', uuid: 'uuid1'},
{ name: 'barney', uuid: 'uuid2'}];
let users2 = [{ name: 'joe', uuid:'uuid5'},
{ name: 'joe', uuid: 'uuid1'},
{ name: 'joe', uuid: 'uuid2'}];
The objective is to remove the objects within each list that share the same UUID value.
let users1 = [{ name: 'barney', uuid: 'uuid3'}]; // Objects with uuid1 and uuid2 removed
let users2 = [{ name: 'joe', uuid:'uuid5'}]; // Objects with uuid1 and uuid2 removed
In the following code snippet, I am extracting the UUIDs from the object lists and storing them in separate arrays.
let a =[];
let b = [];
a = users1.map(s => s.uuid); // UUIDs from list 1 ['uuid3', 'uuid1', 'uuid2']
b = users2.map(s => s.uuid); // UUIDs from list 2 ['uuid5', 'uuid1', 'uuid2']
We can then use a library like lodash to find the intersection:
let e = [];
e = _.intersection(a,b); // Intersection = [uuid1, uuid2]
The list e can be utilized to delete the corresponding objects from users1 and users2.
If you have any ideas, suggestions, or examples on how to approach this deletion process, please share!