Unique array in JavaScript


/ Published in: JavaScript
Save to your folder(s)

Thanks to the original author.


Copy this code and paste it in your HTML
  1. Array.prototype.getUnique = function(){
  2. var u = {}, a = [];
  3. for(var i = 0, l = this.length; i < l; ++i){
  4. if(this[i] in u)
  5. continue;
  6. a.push(this[i]);
  7. u[this[i]] = 1;
  8. }
  9. return a;
  10. }

URL: http://stackoverflow.com/questions/1960473/unique-values-in-an-array/1961068#1961068

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.