Nodejs Array Set setItem(value,mode)

Here you can find the source of setItem(value,mode)

Method Source Code

// Adds, removes or toggles a particular value within an array
//  value - value to add
//  mode - +1 to add value, -1 to remove value, 0 to toggle it
Array.prototype.setItem = function(value,mode)
{
   var p = this.indexOf(value);
   if(mode == 0)/*w ww.  ja  v  a  2 s . c  o m*/
      mode = (p == -1) ? +1 : -1;
   if(mode == +1) {
      if(p == -1)
         this.push(value);
   } else if(mode == -1) {
      if(p != -1)
         this.splice(p,1);
   }
};

Related

  1. set()
    Array.prototype.set = function () {
        var copy = this.slice();
        copy.sort()
        var result = "{" + copy[0];
        for (var i = 1; i < copy.length; i++)
            result += "," + copy[i];
        result += "}";
        return result;
    };
    ...
    
  2. set(index, item)
    Array.prototype.set = function(index, item){
      if (index >= this.length){
        this.add(index, item);
      } else {
        this[index] = item;
    
  3. set(key,value)
    Array.prototype.set = function(key,value){
      this[key] = value;
    
  4. setArray(array)
    Array.prototype.setArray = function (array) {
        this.length = array.length;
        for (var i = 0; i < array.length; i++) {
            this[i] = array[i];
    };
    
  5. setTo(targetArray)
    Array.prototype.setTo = function (targetArray) {
        if (!targetArray || targetArray.length < 1)
            return false;
        if(this.length != size)
          for(var i = 0; i < size; i++)
        this.push([]);
        for (var i = 0; i < size; i++) {
            for(var j = 0; j < size; j++)
                this[i][j] = targetArray[i][j];
        return this;
    
  6. setWhere(property, value, setProperty, setValue)
    Array.prototype.setWhere = function (property, value, setProperty, setValue) {
        "use strict";
        for(var i = 0; i < this.length; i++) {
            if(this[i][property] === value) {
                this[i][setProperty] = setValue;
                return;
    };
    ...