Modify URL and add parameter in between the URL using javascript

3928 views javascript

I have a long list of urls to be modified.

For example the url is:

So in the above url I want to add subid=1233 just before the &source=linkkit

like this:

I tried with append, set and replace but did not gave the specific result

Any suggestions ?

answered question

Why do you need to add it before? It's a query string so no matter where you add it..

The order of parameters in the url doesn't matter unless your endpoint is parsing it explicitly and requires that order

Well, when the actual url is opened in the browser it tracks some data and redirects the url to @PatrickEvans

@KamleshKatpara that has nothing to do with the order of parameters

1 Answer


You can do something like:

let url = '';

url = url.replace('&source=', '&subid=1233&source=')

posted this

Have an answer?


Please login first before posting an answer.