JSFiddle - React, Tailwind, and code Playground
JavaScript
var href = new URL('https://google.com?q=cats');
href.searchParams.set('q', 'dogs');
alert(href);
var href = new URL('https://google.com?q=cats');
href.searchParams.set('q', 'dogs');
alert(href);