Array.prototype.filter() or even a simple
Set object is described as a collection of values, where each value may occur only once. A
Set object is also iterable, making it easily convertible to an array using the spread (
const nums = [1, 2, 2, 3, 1, 2, 4, 5, 4, 2, 6]; [...new Set(nums)] // [1, 2, 3, 4, 5, 6]
You can wrap this in a helper method, which is exactly what the uniqueElements snippet does. For more complex cases, such as unique objects in an array based on a specific key, you might want to take a look at uniqueElementsBy.