I have a url like "http://localhost:8080/myapp?age=12&add=mumbai&name=myname" Now I want to add one parameter(tel=12345) as the first parameter in the query string like "http://localhost:8080/myapp?tel=12345&age=12&add=mumbai&name=myname"
I have tried below snippet
var str = "http://localhost:8080/myapp?age=12&add=mumbai&name=myname";
var txt2 = str.slice(0, str.indexOf("?")) + "tel=12345&" + str.slice(str.indexOf("?"));
alert(txt2);
But the result is incorrect
http://localhost:8080/myapptel=12345&?age=12&add=mumbai&name=myname
Is there a better way???