JS: Uniquify an array


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



Copy this code and paste it in your HTML
  1. Array.prototype.unique = function () {
  2. var r = new Array();
  3. o:for(var i = 0, n = this.length; i < n; i++)
  4. {
  5. for(var x = 0, y = r.length; x < y; x++)
  6. {
  7. if(r[x]==this[i])
  8. {
  9. continue o;
  10. }
  11. }
  12. r[r.length] = this[i];
  13. }
  14. return r;
  15. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.