Nodejs Array Append Item add(index, element)

Here you can find the source of add(index, element)

Method Source Code

/** Adds the specified element to the end of this array. */
Array.prototype.add = function(index, element) {
  if (arguments.length == 2) {
    this.splice(index, 0, element);//from   w w  w . java  2 s .co m
  } else {
    this.push(index);
  }
};

Related

  1. add(e)
    Array.prototype.add = function (e) {
        this.push(e);
    };
    
  2. add(el)
    Array.prototype.add = function(el) {
      this.push(el);
      return this;
    };
    
  3. add(el)
    Array.prototype.add = function (el) {
        var index = this.indexOf(el);
        if (index == -1) {
            this.push(el);
    };
    Array.prototype.remove = function (el) {
        var index = this.indexOf(el);
        if (index > -1) {
    ...
    
  4. add(element)
    Array.prototype.add = function(element) {
      var newSize = this.push(element);
      return newSize-1;
    
  5. add(elemento,duplicado)
    Array.prototype.add = function(elemento,duplicado) {
      if(duplicado===false){
        for (var i = 0; i < this.length; i++) {
          if(this[i]===elemento)
            return;
      this[this.length] = elemento;
    
  6. add(index, item)
    Array.prototype.add = function(index, item){
      if (item === undefined){
        item = index;
        index = 0;
      while (index > this.length){
        this.push(undefined);
      this.splice(index, 0, item);
    ...
    
  7. add(item)
    var SEP = ',';
    Array.prototype.add = function(item) {
        for ( var i = 0; i < this.length; i++) {
            if (this[i] === item) {
                return this;
        this[this.length] = item;
        return this;
    ...
    
  8. add(obj)
    Array.prototype.add = function (obj) {
        var i = this.length;
        this[i] = obj;
        return i;
    };
    
  9. add(other)
    Array.prototype.add = function(other) {
        console.assert(this.length == other.length, 'add: len(a) != len(b)');
        var ret = new Array(this.length);
        for(var i = 0; i < ret.length; i++)
            ret[i] = this[i] + other[i];
        return ret;