Skip to content

Instantly share code, notes, and snippets.

@pirate
Last active December 15, 2023 07:17
Show Gist options
  • Star 54 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save pirate/9298155edda679510723 to your computer and use it in GitHub Desktop.
Save pirate/9298155edda679510723 to your computer and use it in GitHub Desktop.
Parse URL query parameters in ES6
function getUrlParams(search) {
const hashes = search.slice(search.indexOf('?') + 1).split('&')
const params = {}
hashes.map(hash => {
const [key, val] = hash.split('=')
params[key] = decodeURIComponent(val)
})
return params
}
console.log(getUrlParams(window.location.search))
@marcodpt
Copy link

marcodpt commented May 9, 2021

I create an alternative project if you want to use es6 module, with a very simple api:
query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment