Set preserves insertion order and collapses repeated primitive values. Objects still compare by reference.
Worked example
const values = [1, 2, 2, 3];
console.log([...new Set(values)]);Result
[ 1, 2, 3 ]Implementation notes
A key projection is necessary when two different objects represent the same record. Establish whether the first or last record should win before deduplicating.
Try it yourself
Pass two separate objects with identical properties and observe the difference.
Open the JavaScript example →Editorial date November 13, 2025 · Published December 6, 2026