Skip to content

Instantly share code, notes, and snippets.

@dturton
Last active October 20, 2021 15:25
Show Gist options
  • Save dturton/fe82260c39c11bd892a109f00593e76a to your computer and use it in GitHub Desktop.
Save dturton/fe82260c39c11bd892a109f00593e76a to your computer and use it in GitHub Desktop.
URL parameters to a JavaScript object
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