Last active
October 20, 2021 15:25
-
-
Save dturton/fe82260c39c11bd892a109f00593e76a to your computer and use it in GitHub Desktop.
URL parameters to a JavaScript object
This file contains 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 toParameterObject = (search) => | |
JSON.parse( | |
'{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', | |
(key, value) => (key === "" ? value : decodeURIComponent(value)) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment