Skip to content

Instantly share code, notes, and snippets.

@brsc2909
Created March 30, 2022 11:38
Show Gist options
  • Save brsc2909/d7c7026fb3c8837c900a524461e63fbf to your computer and use it in GitHub Desktop.
Save brsc2909/d7c7026fb3c8837c900a524461e63fbf to your computer and use it in GitHub Desktop.
easily get url search params from list
function getSearchParams() {
const query = new URLSearchParams(window.location.search);
const filters = ["client_group", "platform", "date_since", "date_until"];
const filterObject = Object.assign(
{},
...filters.map((filter) => {
const value = query.get(filter);
if (value) return { [filter]: query.get(filter) };
})
);
return filterObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment