I am trying to add a query search parameter onto a URL, it is getting all the parts but not putting them together. The alerts are just my debugging.
let barcode = "123";
alert(barcode); // correctly shows the numerical version of the barcode
const url = new URL("https://example.com/library/search.by.code.php");
const params = new URLSearchParams(url.search);
alert(url); // shows the url correctly
params.set('code', barcode);
params.toString();
alert(params); // correctly shows "code=67862323"
alert(url); // still shows url without parameters