Why does this deduplication helper still return duplicate users?

I expected this helper to keep only the first user for each id, but I still get duplicates in some cases. What am I misunderstanding about how Set works here, and what would be a clean fix without turning this into O(n^2)?

const users = [
  { id: 1, name: 'A' },
  { id: 2, name: 'B' },
  { id: 1, name: 'A2' }
];

const unique = [...new Set(users)];
console.log(unique);

Yoshiii :slightly_smiling_face:

Set only dedupes by object reference, so two different { id: 1 } objects both stay.

BayMax