1var url = new URL('http://demourl.com/path?id=100');
2var search_params = url.searchParams;
3
4// add "topic" parameter
5search_params.set('topic', 'main');
6
7url.search = search_params.toString();
8
9var new_url = url.toString();
10
11// output : http://demourl.com/path?id=100&topic=main
12console.log(new_url);