Created
July 25, 2013 19:51
-
-
Save psdtohtml5/6083140 to your computer and use it in GitHub Desktop.
JavaScript : Get distinct / unique values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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