-3

Custom prototype function for string interpolation

 var str = "user";

console.log("hello {0}".format(str ));
sathish
  • 32
  • 9

1 Answers1

-1

I Found here the answer from another question

Here

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' }));
sathish
  • 32
  • 9