Skip to content

Instantly share code, notes, and snippets.

@Samda
Created December 14, 2021 07:45
Show Gist options
  • Save Samda/3118da774093edec73e5b8cdab578d05 to your computer and use it in GitHub Desktop.
Save Samda/3118da774093edec73e5b8cdab578d05 to your computer and use it in GitHub Desktop.
Parse url params to object
const parseParams = (querystring) => {
// parse query string
const params = new URLSearchParams(querystring);
const obj = {};
// iterate over all keys
for (const key of params.keys()) {
if (params.getAll(key).length > 1) {
obj[key] = params.getAll(key);
} else {
obj[key] = params.get(key);
}
}
return obj;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment