Skip to content

Instantly share code, notes, and snippets.

@bhaireshm
Created October 12, 2020 06:55
Show Gist options
  • Save bhaireshm/6db24c24dbd6f77a82733d8f49cccd83 to your computer and use it in GitHub Desktop.
Save bhaireshm/6db24c24dbd6f77a82733d8f49cccd83 to your computer and use it in GitHub Desktop.
Converting URL query parameters to object in javascript.
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