JavaScript string format like python

Below is an example of using JavaScript string format like python

if (!String.prototype.format) { String.prototype.format = function () { var i = 0, args = arguments; return this.replace(/{}/g, function () { return typeof args[i] != 'undefined' ? args[i++] : ''; }); }; } var text1 = 'John', text2 = 'JavaScipt', text3 = 'python'; 'Hello world, my name is {} .I love {} and {}'.format(text1, text2, text3); // "Hello world, my name is John .I love JavaScipt and python"
Code language: JavaScript (javascript)

Leave a Reply