Skip to content

Instantly share code, notes, and snippets.

@40
Created July 19, 2012 08:13
Show Gist options
  • Select an option

  • Save 40/3141523 to your computer and use it in GitHub Desktop.

Select an option

Save 40/3141523 to your computer and use it in GitHub Desktop.
Unique Values in Array
// Original Source: http://stackoverflow.com/questions/1960473/unique-values-in-an-array
// 1. Variation 1
var a = [1,5,1,6,4,5,2,5,4,3,1,2,6,6,3,3,2,4];
// note: jQuery's filter params are opposite of javascript's native implementation :(
var unique = $.makeArray($(a).filter(function(i,itm){
// note: 'index', not 'indexOf'
return i == $(a).index(itm);
}));
// unique: [1, 5, 6, 4, 2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment