JSFiddle - React, Tailwind, and code Playground

by harperj1029

JavaScript

String.format = function() {
    var args = Array.prototype.slice.call(arguments).slice(1);
    return arguments[0].replace(/{(\d+)}/g, function(match, number) { 
        return typeof args[number] != 'undefined' ? args[number] : match;
    });
};
String.prototype.format = function(){
    var args = Array.prototype.slice.call(arguments);
    args.unshift(this);
    return String.format.apply(this,args);
};
document.write(String.format('{0} world','hello') + '<br/>');
document.write('{0} world'.format('hello'));