URLSearchParams 1


let params = new URLSearchParams('foo=2'); // "location.search" to read from URL

params.append('bar', 4);                   //Add a bar parameter.
console.log(params.toString());            //Prints 'foo=2&bar=4'

location.search = params.toString();       // write changes to URL

Here is what the above code is Doing:
1. Create a new URLSearchParams object with the value of location.search.
2. Add a bar parameter with the value of 4.
3. Print the new query string to the console.
4. Write the new query string to the URL.

Similar Posts