Created
March 30, 2022 11:38
-
-
Save brsc2909/d7c7026fb3c8837c900a524461e63fbf to your computer and use it in GitHub Desktop.
easily get url search params from list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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