JavaScript format string

JavaScript format string similarly to python's string format.

String.format = function(format) {
    var args = Array.prototype.slice.call(arguments, 1);
    return format.replace(/{(\d+)}/g, function(match, number) {
        return typeof args[number] != 'undefined' ? args[number] : match;
    });
};

https://docs.python.org/3/library/stdtypes.html#str.format

http://stackoverflow.com/questions/610406/

Did this help you? Please let me know with a comment. Thank you
Posted .

Comments (RSS)

Leave a comment