String.prototype.replaceAt=function(index, ch) {
return this.substr(0, index) + ch + this.substr(index + ch.length);
}
function swap(s, index1, index2) {
var tmp = s[index1];
s = s.replaceAt(index1, s[index2]);
s = s.replaceAt(index2, tmp);
return s;
}
s = "ayzd";
s = swap(s, 2, 3);
document.write(s);
/*
run:
aydz
*/