Javascript String strtr(replacePairs)

Description

Javascript String strtr(replacePairs)


String.prototype.strtr = function (replacePairs) {
    "use strict";
    var str = this.toString(), key, re;
    for (key in replacePairs) {
        if (replacePairs.hasOwnProperty(key)) {
            re = new RegExp(key, "g");
            str = str.replace(re, replacePairs[key]);
        }//from   w  ww .j  a v  a2  s  . c  om
    }
    return str;
};



PreviousNext

Related