Skip to content

Instantly share code, notes, and snippets.

@paulmwatson
Created June 7, 2021 12:42
Show Gist options
  • Save paulmwatson/828564e177e33420e6e69ce314e8deb3 to your computer and use it in GitHub Desktop.
Save paulmwatson/828564e177e33420e6e69ce314e8deb3 to your computer and use it in GitHub Desktop.
Manipulating the query string with URLSearchParams
const url = 'https://host.test/path/here.filetype?query=string&more=params#anchor';
let newUrl = new URL(url);
let params = new URLSearchParams(newUrl.search);
params.set('query', `${params.get('query')}-changed`);
params.delete('more');
params.set('new', 'param');
newUrl.search = params;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment