Last active
October 16, 2022 11:38
-
-
Save mpecka/a5ffa84a718802d567664cb12b29cbd2 to your computer and use it in GitHub Desktop.
Parse location.search query parameters (convert to 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
| function getQueryParams(url) { | |
| const paramArr = url.slice(url.indexOf('?') + 1).split('&'); | |
| const params = {}; | |
| paramArr.map(param => { | |
| const [key, val] = param.split('='); | |
| params[key] = decodeURIComponent(val); | |
| }) | |
| return params; | |
| } | |
| getQueryParams('https://example.com/search?q=node&page=2') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment