Instead of creating an `` element, you could use `new URLSearchParams(window.location.search)`. Also in node you could require the `url` lib and use it with `URLSearchParams` or `URL`. If you don't want to split the string yourself you could initialize an `URL` and then access the `url.search` for the search string, or `searchParams` for access the interface of `URLSearchParams`.
Splitting the new URL on the question mark in the 3rd example seemed like a quick solution (although one I'd probably use myself) rather than rebuild the URL from the location.protocol, host and pathname parts. Still, all these options work so it's all good. :-)
Hey quick question, what's the name of the VSCode extension that it tells you the value / type etc. of an element or variable when you do //? ? Thanks in advance :D
I knew this wouldn't have the real JavaScript solution as soon as I saw `const URL`. Best JavaScript solution: const url = new URL('...'); url.searchParams.delete('gclid'); Done.
Each time I needed query params to be allowed in the URL I've always used ?something=value. However, few months ago I needed to convert a JSON object into a query parameter to be passed in the URL and my colleague asked me why would I use such technique to pass the object in the URL rather than having a stringified JSON object pasted in the URL directly. Whilst this sound very ugly to me I could not really provide him an answer more than that most websites pass parameters in the url with ?something=value. What would be the drawback to have example.com/'{"something":"value"}" over the more common practise of ?something=value ?
You have to escape the characters (so not you happen to have a ”/” that the browser thinks is a path). So a { becomes %7B. Each necessary character in the JSON format takes unnecessary space and you risk of oretty fast rinning into the length limit of urls. See this post blogs.dropbox.com/developers/2015/03/json-in-urls/