[JavaScript] Remove duplicate values from an array

Created on November 30, 2026

Construct a Set from the array to keep each value once. Then convert the set back into an array with Array.from(). The values stay in the order of their first occurrence.

const arr = ['one', 'two', 'one', 'three'];
console.log(JSON.stringify(Array.from(new Set(arr))));
["one","two","three"]
JavaScript