Skip to content

Instantly share code, notes, and snippets.

@ShahirZain
Created December 12, 2021 13:52
Show Gist options
  • Save ShahirZain/c22b0d5f75057738417a41c70a66bd77 to your computer and use it in GitHub Desktop.
Save ShahirZain/c22b0d5f75057738417a41c70a66bd77 to your computer and use it in GitHub Desktop.
How to get QueryParams in modern JavaScript
export const getQueryParams = queryParams => {
const urlParams = new URLSearchParams(queryParams);
return Array.from(urlParams.entries()).reduce((acc, [key, value]) => {
acc[key] = value;
return acc;
}, {});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment