This question already has an answer here:
- Equivalent of String.format in jQuery 19 answers
C# has the really powerful String.Format()
for replacing elements like {0}
with parameters. Does JavaScript have an equivalent?
This question already has an answer here:
C# has the really powerful |
||||
marked as duplicate by Satpal Nov 10 '14 at 8:57This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. |
||||
Or
Both answers pulled from JavaScript equivalent to printf/string.format |
|||||
|
I am using:
usage: I found it at Equivalent of String.format in JQuery UPDATED: In ES6/ES2015 you can use string templating for instance
|
|||||||||
|
Based on @Vlad Bezden answer I use this slightly modified code because I prefer named placeholders:
usage:
|
||||
|
I created it a long time ago, related question
|
|||||
|
JavaScript !== jQuery
. There's not even a jQuery tag. You could argue this question ("JavaScript equivalent to printf/string.format") is the correct "original", but the currently linked one isn't. – ruffin Jun 10 '15 at 14:55'{name} is {mood}'.replace('{name}', 'Tobi').replace('{mood}', 'happy')
– ilyaigpetrov Aug 19 '15 at 2:01