Javascript Array swap(index1, index2)
Array.prototype.swap = function(index1, index2) { var temp = this[index1]; this[index1] = this[index2];//from w w w. j a v a 2 s . c o m this[index2] = temp; };