I am using:
String.prototype.format = function() {
var s = this,
i = arguments.length;
while (i--) {
s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
}
return s;
};
usage: "Hello {0}".format("World");
I found it at Equivalent of String.format in JQuery
UPDATED:
In ES6/ES2015 you can use string templating for instance
'use strict';
let firstName = 'John',
lastName = 'Smith';
console.log(`Full Name is ${firstName} ${lastName}`);
// or
console.log(`Full Name is ${firstName + ' ' + lastName}');