const arr = [1, 2, '2', 3, 3, 4, 4, 5];
const result = [...new Set(arr)];
console.log(result);
output:
[ 1, 2, '2', 3, 4, 5 ]
- Here, in the above code the line const result = […new Set(arr)] removes duplicate values from the array
arrusing aSet, which only allows unique values. new Set(arr): Creates a newSetfrom the array. TheSetwill only keep unique values.[...new Set(arr)]: The spread operator...is used to convert theSetback into an array.