Skip to content

Instantly share code, notes, and snippets.

@giovanigenerali
Created July 22, 2018 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giovanigenerali/7b9103f821c82ca6fc44ebe84e883e60 to your computer and use it in GitHub Desktop.
Save giovanigenerali/7b9103f821c82ca6fc44ebe84e883e60 to your computer and use it in GitHub Desktop.
getParamsFromURL
const getParamsFromURL = (url) => {
return decodeURIComponent(new URL(url).search.substr(1))
.split('&')
.reduce((acc, cur) => {
const [key, value] = cur.split('=')
acc[key] = value
return acc
}, {})
}
const params = getParamsFromURL('https://localhost/resource/?param1=value1&param2=value2');
console.log(params);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment