Oct 28, 2013 at 13:21. Here is an example: Url: slice (1); // What is the advantage of one is the disadvantage of the other. how to add query params in url. The URLSearchParams constructor takes in the query parameters part of a URL. The query string is first separated to get only the parameters portion of the string. (&|$)", "i"); var separator = url.indexOf('?') The set method can also be used to add a new parameter value: params. let url = new URL('https://example.com?foo=1&bar=2'); let params = new URLSearchParams(url.search); //Add a second foo parameter. [1]: window. So in this article, we will give you a simple function that will help you to get the value of query string parameters.