Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
Created July 25, 2013 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psdtohtml5/6083140 to your computer and use it in GitHub Desktop.
Save psdtohtml5/6083140 to your computer and use it in GitHub Desktop.
JavaScript : Get distinct / unique values
// Get distinct values from an array
$.extend({
distinct : function(anArray) {
var result = [];
$.each(anArray, function(i,v){
if ($.inArray(v, result) == -1) result.push(v);
});
return result;
}
});
var arrValues = [1,1,2,3,4,4,5,6,6];
var arrUniques = $.distinct(arrValues);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment