[Solved] javascript array text substitution


Okay, so this works: http://jsfiddle.net/4ax7mvL4/5/

var a = [];
a[0] = "Hi may name is '%s' and my brother is '%d'";
a[1] = "John";
a[2] = "David";
var final = a[0];

for(var i = 1; i < a.length; i++) {
    final = final.replace(/%[sd]/, a[i]);
}
alert(final);

But I’m sure there are people out there that could optimize it and make it nicer looking 🙂

3

solved javascript array text substitution