Joined March 2018
·

malla

Posted to Simple String.format() in javascript over 1 year ago

Thanks! I made a small improvement so that all instances are replaced rather than just the first. :)

String.prototype.format = function () {
        var a = this;
        for (var k in arguments) {
            a = a.replace(new RegExp("\\{" + k + "\\}", 'g'), arguments[k]);
        }
        return a
    }
Achievements
1 Karma
0 Total ProTip Views