Treats arrays as set and adds the new elements - Node.js Array

Node.js examples for Array:Array Value

Description

Treats arrays as set and adds the new elements

Demo Code


// Treats arrays as set and adds the new elements
Array.prototype.addSet = function(values){
    for(var i=0; i < values.length; i++){
        if(this.indexOf(values[i]) == -1) this.push(values[i]);
    }/*from  w  w w.j  av a  2 s  .c  o  m*/
}

Related Tutorials