Get unique element from array - Node.js Array

Node.js examples for Array:Unique Element

Description

Get unique element from array

Demo Code


Array.prototype.getUnique = function(){
   var u = {}, a = [];
   for(var i = 0, l = this.length; i < l; ++i){
      if(u.hasOwnProperty(this[i])) {
         continue;//from   ww w. j  av  a2  s  .  c  o m
      }
      a.push(this[i]);
      u[this[i]] = 1;
   }
   return a;
}

Related Tutorials