Created
November 27, 2017 10:08
-
-
Save sharmaabhinav/bec27739098e2dd7e3bbc6f523d138d0 to your computer and use it in GitHub Desktop.
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
var re = /\{\d\}/ | |
var str = 'My name is {0} . My location is {1}. My country is {2}' | |
function formatter (str) { | |
var params = Array.prototype.splice.call(arguments, 1) | |
for(var i=0;i<params.length;i++){ | |
str = str.replace(re, params[i]) | |
} | |
return str | |
} | |
console.log(formatter(str, 'abhinav', 'sharma', 'india')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment