Remove duplicate value from array - Node.js Array

Node.js examples for Array:Remove Element

Description

Remove duplicate value from array

Demo Code

Array.prototype.removeDups = function(){

    var result = [];

    for(var i = 0; i < this.length; i++){
       if(result.indexOf(this[i]) < 0){
           result.push(this[i]);//from   w ww .  j  a v  a 2s.  co  m
       }
    }

    return result;

}

console.log([1, 1, 2, 3, 2].removeDups());

Related Tutorials