Nodejs Array Object Key addIfUnique(key, value)

Here you can find the source of addIfUnique(key, value)

Method Source Code

Array.prototype.addIfUnique = function(key, value)
{
   if(this.contains(key))
      this[key] = value;//from   w w w .  ja  va  2 s .  c o m
   else
   {
      this.push(key);
      this[key] = value;
   }
}

Related

  1. by( key, id )
    Array.prototype.by = function( key, id )
      var index = this.length;
      while( index-- )
        if( this[ index ][ key ] == id ) {
          return this[ index ];
    };
    
  2. changeItem( key, property, value )
    Array.prototype.changeItem = function( key, property, value )
      var done = false;
        for(var i = 0; i < this.length; i++)
            if( this[i]["id"] == key)
              this[i][property] = value ; done = true;
        return done;
    };
    
  3. containsProp(key,str)
    Array.prototype.containsProp = function(key,str) {
      var i = this.length,
        holder = [];
      while (i--) {
        if (this[i][key] === str) {
          holder.push(this[i]);
      return holder;
    ...
    
  4. containsReturn(key, value)
    Array.prototype.containsReturn = function(key, value) {
        var i = this.length;
        while (i--) {
            if (this[i][key] === value){
                return i;
        return false;