Printf function - Node.js String

Node.js examples for String:Format

Description

Printf function

Demo Code


// format function borrowed from http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format/4673436#4673436
String.prototype.format = function () {
    var args = arguments;
    return this.replace(/{(\d+)}/g, function (match, number) {
        return typeof args[number] != 'undefined'
          ? args[number]// w  w w  .  java  2s . co m
          : match
        ;
    });
};

Related Tutorials