Created
October 13, 2023 14:11
-
-
Save Potherca/201d48974488b36b7eebde95eb727fac to your computer and use it in GitHub Desktop.
set search params on an URL in javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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