I am working quite a bit with Maps in javascript. I need the most computationally efficient way to find all items that are in Map a that are not present in Map b. For example,
const a = new Map();
a.set('item1', 'item1value');
a.set('item2', 'item2value');
const b = new Map();
b.set('item1', 'item1value');
The result of the function I'm looking to write would be another Map, with a single entry of key: item2
, value: item2value
.
I am well aware of the multitude of questions / answers / methods to do this with arrays and objects, however I have not seen such an explanation for maps. I need the absolute most efficient way to do so, as I will need to be call this function up to thousands of times quickly. Is conversion to an array and back to a Map the best way? Are there any tricks with Maps that may help?