In the description of jQuery.unique() method in the official docs I found that:
… this only works on arrays of DOM elements, not strings or numbers.
However, if we try the method for some test arrays with strings or numbers it seems to work fine:
$.unique(["Alex", "Andrew", "Maria", "Alex", "Nick", "Andrew", "Eugene"]);
// ["Eugene", "Nick", "Maria", "Andrew", "Alex"]
$.unique([1, 3.5, -1e5, 2, 3.5, 1, 1000, -1e5]);
// [1000, 2, -100000, 3.5, 1]
What is the point?
By limiting the scope of what the documentation says it can do, they have the flexibility of changing it later if necessary without having to worry about supporting more than the documented functionality.
The current implementation (which is actually just a reference to
Sizzle.uniqueSortfrom the Sizzle selector engine built into jQuery) mostly just compares things with===, which explains why it works fine for strings and numbers as well. But by limiting the scope, they can change that in the future if there’s some more efficient way to do it they find later (but which only works with DOM elements).Note that it’s primarily an internal method, as the docs also say: