Skip to content

Instantly share code, notes, and snippets.

@VincentHelwig
Created November 5, 2014 11:23
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 VincentHelwig/b1a555e7c7c4c4393978 to your computer and use it in GitHub Desktop.
Save VincentHelwig/b1a555e7c7c4c4393978 to your computer and use it in GitHub Desktop.
Get unique array
// FROM http://jsperf.com/compare-array-unique-versions/4
Array.prototype.getUnique = function () {
var arr = this;
var newArr = [],
i = 0,
j = 0,
obj = {},
len = arr.length;
while (len--) {
if (!obj[arr[i]]) {
obj[arr[i]] = 1;
newArr[j] = arr[i];
j++;
}
i++;
}
return newArr;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment