Javascript Array filterUnique()

Description

Javascript Array filterUnique()


Array.prototype.filterUnique = function() {
 var arr = [];/* www .  j  av a  2  s  . c o m*/
 var orig = this;

 orig.forEach(function(a, i) {
  if (arr.indexOf(a) < 0) {
   arr.push(a);
  } else {
   orig.splice(i, 1);
  }
 });

 return orig;
};



PreviousNext

Related