/ Published in: JavaScript

Ensures all elements in an array are unique
newArray = myArray.unique();
newArray = myArray.unique();
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
Array.prototype.unique = function() { var newArray=new Array(); label:for (var i=0; i < this.length; i++) { for (var j=0; j < newArray.length; j++) { if (newArray[j] == this[i]) continue label; } newArray[newArray.length] = this[i]; } return newArray; }
Comments
