Created
October 12, 2020 06:55
-
-
Save bhaireshm/6db24c24dbd6f77a82733d8f49cccd83 to your computer and use it in GitHub Desktop.
Converting URL query parameters to object in javascript.
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
let search = location.search.substring(1), urlParams; | |
urlParams = JSON.parse( | |
'{"' + search.replace(/&/g, '","').replace(/=/g, '":"') + '"}', | |
function (key, value) { | |
return key === "" ? value : decodeURIComponent(value); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment