Swap letter in a String - Node.js String

Node.js examples for String:String Value

Description

Swap letter in a String

Demo Code

String.prototype.swap = function(a, b) {
    var array = this.split('');
    var tmp = array[a];
    array[a] = array[b];/*from   ww w  .ja v  a2s . c o  m*/
    array[b] = tmp;
    return array.join('');
}

Related Tutorials