Last active
December 17, 2015 00:09
-
-
Save dmiro/5518602 to your computer and use it in GitHub Desktop.
Apply string format to all elements of array and return result
This file contains hidden or 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
| // 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; | |
| }; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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' ]