Nodejs Array Remove Duplicate removeDuplicate()

Here you can find the source of removeDuplicate()

Method Source Code

Array.prototype.removeDuplicate = function() {
   return this.reduce(function(last,current){
      if(last.indexOf(current) === -1){
         last.push(current);//from  w w w.ja  v a  2  s  .  c om
      }
      return last;
   },[])
};



var array = [1,1,2,1,3,4,12,4,5,,12,3,4];
var a = array.concat([]);
a = a.filter(function(item, pos) {
    return a.indexOf(item) == pos;
})
console.log(a)

console.log(array.removeDuplicate());

Related

  1. removeDuplicate()
    Array.prototype.removeDuplicate = function()
      var tmp = [];
      var agent = {};
      for( var i = 0; i < this.length; i++ )
        if( !agent.hasOwnProperty( this[ i ] ) )
          agent[ this[ i ] ] = { val: this[ i ], index: i };
      console.log( agent );
      for( var ns in agent )
        var d = agent[ ns ];
        tmp[ d.index ] = d.val;
      for( i = tmp.length - 1; i > 0; i-- )
        if( is_empty( tmp[ i ] ) ) tmp.splice( i, 1 );
      return tmp;
    };
    
  2. removeDuplicateDates()
    Array.prototype.removeDuplicateDates = function() {
      var u = [];
      for ( var i = 0; i < this.length; i++ ) {
        var current = new Date(this[i]);
        if ( u.map(Number).indexOf(+current) < 0 ) {
          u.push(current);
      return u;
    ...
    
  3. removeDuplicateValues()
    Array.prototype.removeDuplicateValues = function () {
        return this.filter(function (elem, pos, self) {
            return self.indexOf(elem) == pos;
        });
    
  4. removeDuplicateValues()
    Array.prototype.removeDuplicateValues = function () {
        return this.filter(function (elem, pos, self) {
            return self.indexOf(elem) === pos;
        });
    };