-
-
Save Foodguru/4007261 to your computer and use it in GitHub Desktop.
javascript: String Format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.format = function() { | |
var formatted = this; | |
for (var i = 0; i < arguments.length; i++) { | |
var regexp = new RegExp('\\{'+i+'\\}', 'gi'); | |
formatted = formatted.replace(regexp, arguments[i]); | |
} | |
return formatted; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment