Skip to content

Instantly share code, notes, and snippets.

@psdtohtml5
Created July 28, 2013 13:44
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/6098630 to your computer and use it in GitHub Desktop.
Save psdtohtml5/6098630 to your computer and use it in GitHub Desktop.
JavaScript : Count unique items in an array
$.extend({
countUnique : function(array) {
var result = [];
$.each(array, function(i,v) {
if($.inArray(v, result) == -1) {
result.push(v);
}
});
return result.length;
}
});
var array = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5];
$.countUnique(array);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment