Zest.

JavaScript: Remove duplicates from an array

A short, tested JavaScript example for remove duplicates from an array. Copy it and adjust the names and paths for your project.

JavaScript
const unique = [...new Set([3, 1, 3, 2, 1])];   // [3, 1, 2]

// objects by key
const byId = [...new Map(items.map(i => [i.id, i])).values()];

Find it in Zest

Search for “javascript remove duplicates from an array” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More JavaScript examples

All JavaScript examples