Skip to content

Instantly share code, notes, and snippets.

@nmenglund
Created September 17, 2013 08:25
Show Gist options
  • Select an option

  • Save nmenglund/6591546 to your computer and use it in GitHub Desktop.

Select an option

Save nmenglund/6591546 to your computer and use it in GitHub Desktop.
JS: Simple string formatter
String.prototype.format = function() {
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number) { return ((typeof args[number] != 'undefined') ? args[number]: match); });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment