Nodejs Array Set set()

Here you can find the source of set()

Method Source Code

// returns the array as a string with set notation 
// e.g.: [1,2,3] -> {1,2,3}
Array.prototype.set = function () {
    var copy = this.slice();
    copy.sort()//from ww w  .  java  2s .co m
    var result = "{" + copy[0];
    for (var i = 1; i < copy.length; i++)
        result += "," + copy[i];
    result += "}";
    return result;
};

Related

  1. set(index, item)
    Array.prototype.set = function(index, item){
      if (index >= this.length){
        this.add(index, item);
      } else {
        this[index] = item;
    
  2. set(key,value)
    Array.prototype.set = function(key,value){
      this[key] = value;
    
  3. setArray(array)
    Array.prototype.setArray = function (array) {
        this.length = array.length;
        for (var i = 0; i < array.length; i++) {
            this[i] = array[i];
    };
    
  4. setItem(value,mode)
    Array.prototype.setItem = function(value,mode)
      var p = this.indexOf(value);
      if(mode == 0)
        mode = (p == -1) ? +1 : -1;
      if(mode == +1) {
        if(p == -1)
          this.push(value);
      } else if(mode == -1) {
    ...