Nodejs Array Add All addAll(index, elements)

Here you can find the source of addAll(index, elements)

Method Source Code

/** Adds all of the specified elements to the end of this array. */
Array.prototype.addAll = function(index, elements) {
  if (arguments.length == 2) {
    var n = this.length, m = elements.length;
    this.length += m;/*from  w  ww  .j a v a 2s  . c o  m*/
    for (var i = n - 1; i >= index; i--) {
      this[i + m] = this[i];
    }
    for (var i = 0; i < m; i++) {
      this[i + index] = elements[i];
    }
  } else {
    for (var i = 0; i < index.length; i++) {
      this.push(index[i]);
    }
  }
};

Related

  1. addAll( list )
    Array.prototype.addAll = function( list ) {
      for( var i=0; i<list.length; i++ ) {
        this.push( list[i] );
      return this;
    };
    
  2. addAll(addingElements)
    Array.prototype.addAll = function(addingElements) {
      for (var elementIndex = 0; elementIndex < addingElements.length; ++elementIndex) {
        this.push(addingElements[elementIndex]);
    };
    
  3. addAll(arr)
    Array.prototype.addAll = function (arr) {
        var len = arr.length;
        for (var i = 0; i < len; i++) {
            this.push(arr[i]);
    };
    
  4. addAll(arr)
    "use strict";
    Array.prototype.addAll = function (arr) {
        for (const elm of arr) {
            this.push(elm);
    };
    if (!Array.prototype.includes) {
        Array.prototype.includes = function (element) {
            return this.indexOf(element) > -1;
    ...
    
  5. addAll(index, items)
    Array.prototype.addAll = function(index, items){
      if (items === undefined){
        items = index;
        index = 0;
      for (var i=0; i<items.length; i++){
        this.add(index+i, items[i]);
      return true;
    ...
    
  6. addAll(items)
    Array.prototype.addAll = (items) => {
        this.push.apply(this, items);
        this.push(null);
        this.pop();