Skip to content

Instantly share code, notes, and snippets.

@jpiccari
Created June 29, 2014 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpiccari/b287bacb14fb933598d5 to your computer and use it in GitHub Desktop.
Save jpiccari/b287bacb14fb933598d5 to your computer and use it in GitHub Desktop.
/**
* Creates a string using indexed format string
* @param {string} Format of string
* @param {...string} One or more strings to be using in the format
*/
function formatString(/* ... */) {
var args = Array.apply(0, arguments);
return args.shift().replace(/\{(\d+)\}/g, function(match, index) {
return index < args.length
? args[index]
: match;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment