Skip to content

Instantly share code, notes, and snippets.

@Potherca
Created October 13, 2023 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Potherca/201d48974488b36b7eebde95eb727fac to your computer and use it in GitHub Desktop.
Save Potherca/201d48974488b36b7eebde95eb727fac to your computer and use it in GitHub Desktop.
set search params on an URL in javascript
const url = new URL(document.location)
const search = new URLSearchParams()
const options = {
"foo": "hello",
"bar":"world"
}
Object.entries(options).forEach(([key, value]) => {
search.append(key, value)
})
url.search = search
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment