jQuery.unique lets you get unique elements of an array, but the docs say the function is mostly for internal use and only operates on DOM elements. Another SO response said the unique()
function worked on numbers, but that this use case is not necessarily future proof because it's not explicitly stated in the docs.
Given this, is there a "standard" jQuery function for accessing only the unique values — specifically, primitives like integers — in an array? (Obviously, we can construct a loop with the each()
function, but we are new to jQuery and would like to know if there is a dedicated jQuery function for this.)
If anyone is using knockoutjs try:
BTW have look at all
ko.utils.array*
utilities.this is js1568's solution, modified to work on a generic array of objects, like:
It accepts one more parameter called propertyName, guess! :)
so, if you need to extract a list of unique values for a given property, for example the values used for randomInt property, use this:
it returns an array like this: