To get all unique values in a JavaScript array, we can convert it to a set and back.
For instance, we write
const myArray = ["a", 1, "a", 2, "1"];
const unique = [...new Set(myArray)];
console.log(unique);
to convert the myArray
array to a set with the Set
constructor.
Then we convert the set back to an array without duplicate values with the spread operator.