Skip to content

Instantly share code, notes, and snippets.

@htmelvis
Created February 14, 2022 14:22
Show Gist options
  • Save htmelvis/71ed4217f75a897db603bb0583679a72 to your computer and use it in GitHub Desktop.
Save htmelvis/71ed4217f75a897db603bb0583679a72 to your computer and use it in GitHub Desktop.
Get Query Params from URL
const getParameters = (URL) => {
URL = JSON.parse('{"' + decodeURI(URL.split("?")[1]).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') +'"}');
return JSON.stringify(URL);
};
getParameters(window.location)
// Result: { search : "easy", page : 3 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment