Javascript Array swapAt(index1, index2)

Description

Javascript Array swapAt(index1, index2)

Array.prototype.swapAt = function (index1, index2) {
  if (index2 === undefined) {
    index2 = this.length - 1;//  w  ww. j a va 2s .  com
  }

  var elementAtIndex1 = this[index1];
  this[index1] = this[index2];
  this[index2] = elementAtIndex1;
  return this;
};



PreviousNext

Related