Simple String.format() in Javascript

1
2
3
4
5
6
7
String.prototype.format = function() {
a = this;
for (k in arguments) {
a = a.replace("{" + k + "}", arguments[k])
}
return a
}

Usage:

1
console.log("Hello, {0}!".format("World"))

https://coderwall.com/p/flonoa/simple-string-format-in-javascript

分享