Swap numbers in JS
by webspicer
JavaScript
var newArray = Array.from("12345");
var n1 = newArray[1];
var n2 = newArray[2];
Array.prototype.remove = function(index) {
this.splice(index, 2);
}
newArray.remove(1, 2);
console.log("Removed"+newArray);
Array.prototype.insert = function (index, item) {
this.splice(index,0, item);
};
newArray.insert(1, n2);
newArray.insert(2, n1);
console.log("Added=="+newArray);