Last active
April 12, 2020 21:36
-
-
Save danierdev/6b487e7dd8f69bcbab4f085f17578b8f to your computer and use it in GitHub Desktop.
Get current query params as plain Object
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 paramsString = document.location.search; | |
const searchParams = new URLSearchParams(paramsString); | |
// You can iterate the search parameters. | |
for (const [key, value] of searchParams) {} | |
for (const [key, value] of searchParams.entries()) {} | |
// Or just get a plain object | |
const objectParams = Object.fromEntries(searchParams.entries()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment