Posted By

riddla on 07/09/10


Tagged

javascript array unique


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

riddla


Unique array in JavaScript


 / Published in: JavaScript
 

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

Thanks to the original author.

  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. }

Report this snippet  

You need to login to post a comment.