Files and data
Compare two lists of identifiers
Use sets to compute identifiers present in one list but absent from another. Label the direction explicitly, because A minus B answers a different question from B minus A.
Worked example
Node.js example · save as example.mjs and run node example.mjs
const before = new Set(["a", "b", "c"]);
const after = new Set(["b", "c", "d"]);
const removed = [...before].filter(id => !after.has(id));
const added = [...after].filter(id => !before.has(id));
console.log(JSON.stringify({removed, added}));How it works
Membership checks compare identifier values. The removed list starts with the earlier snapshot, while the added list starts with the later snapshot. This simple report is useful for inventory exports, subscription lists, or other stable-ID datasets.
Limits and mistakes
Sets discard duplicate counts and assume identifiers are normalized consistently. A changed display name is not necessarily a changed entity. Establish stable identity and snapshot completeness before attributing differences to real-world additions or removals.
Check the result
Expect {"removed":["a"],"added":["d"]}. Swap the two inputs and confirm the meanings reverse. Add duplicate IDs to see why this is set comparison rather than quantity comparison.
Sources
Reference documentation for the behavior used in this guide: