I have the following elements:
var url = "http://my.url/$1/$2/$3";
var params = ["unused", "first", "second", "third"];
I want to replace each $n element in the URL for the element in position n in the params array (i.e. $1 will be "first", $2 will be "second" and $3 will be "third").
I have the following code:
var cont=1;
while (params[cont]) {
url = url.replace(new RegExp("\\$" + cont, "gm"), params[cont])
cont++
}
The above code works, but I wonder if there would be a better way to do this replace (without looping).
Thank you very much in advance