The array to search.
A new array containing only the unique elements.
This method filters duplicates by inserting all elements into a Set.
Therefore, each element is compared using same-value-zero equality,
which has the same behavior as Object.is,
except +0
and -0
are considered equal.
unique([1, 2, 3, 2, 1]) // [1, 2, 3]
unique([0, -0, 1]) // [0, 1]
unique([NaN, Number.NaN, NaN]) // [NaN]
Objects are compared by reference.
const foo = { a: 1 }
unique([foo, foo]) // [foo]
const bar = { a: 1 }
unique([foo, bar]) // [foo, bar]
Generated using TypeDoc
Gets only the unique elements of an array.