Dev Helpers

JavaScript / Arrays

Remove duplicate values

Dev Helpers · November 13, 2025

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

Related articles

Chunk an array

Batching work by array slices gives the last batch permission to be shorter. Guard the requested size before using it as the loop increment.

Flatten nested arrays

Choose the flattening depth from the data contract. Flattening another level can erase a meaningful grouping.

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.