Posted By

svenito on 09/29/09


Tagged

array unique


Versions (?)

Ensure all elements in array are unique


 / Published in: JavaScript
 

Ensures all elements in an array are unique

newArray = myArray.unique();

  1. Array.prototype.unique = function() {
  2. var newArray=new Array();
  3. label:for (var i=0; i < this.length; i++) {
  4. for (var j=0; j < newArray.length; j++) {
  5. if (newArray[j] == this[i])
  6. continue label;
  7. }
  8. newArray[newArray.length] = this[i];
  9. }
  10. return newArray;
  11. }

Report this snippet  

You need to login to post a comment.