Skip to content

Instantly share code, notes, and snippets.

@crates
Created January 30, 2019 15:22
Show Gist options
  • Save crates/9085af2aa1fd36cae09bb594b206fb08 to your computer and use it in GitHub Desktop.
Save crates/9085af2aa1fd36cae09bb594b206fb08 to your computer and use it in GitHub Desktop.
Gets the current site's query string and returns it as a JavaScript object
const getQueryStrAsObj = () => {
const paramsToObject = (keys) => { let result = {}; for(let entry of keys) result[entry[0]] = entry[1]; return result };
const params = new URLSearchParams(location.search.substr(1, location.search.length - 1));
return paramsToObject(params.entries());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment