Custom prototype function for string interpolation
var str = "user";
console.log("hello {0}".format(str ));
Custom prototype function for string interpolation
var str = "user";
console.log("hello {0}".format(str ));
I Found here the answer from another question
String.prototype.supplant = function (o) {
return this.replace(/{([^{}]*)}/g,
function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
};
// Usage:
alert("I'm {age} years old!".supplant({ age: 29 }));
alert("The {a} says {n}, {n}, {n}!".supplant({ a: 'cow', n: 'moo' }));