Skip to content

Instantly share code, notes, and snippets.

@dmiro
Last active December 17, 2015 00:09
Show Gist options
  • Select an option

  • Save dmiro/5518602 to your computer and use it in GitHub Desktop.

Select an option

Save dmiro/5518602 to your computer and use it in GitHub Desktop.
Apply string format to all elements of array and return result
// apply string format to all elements of array and return result
Array.prototype.format=function(prefix)
{
var result = [];
this.forEach(function(entry) {
result.push(prefix.format(entry));
});
return result;
};
@dmiro

dmiro commented May 4, 2013

Copy link
Copy Markdown
Author

Example:

var misNumeros = [1,2,3];
console.log(misNumeros.format("soy el numero {0}"));
// return [ 'soy el numero 1', 'soy el numero 2', 'soy el numero 3' ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment