Skip to content

Instantly share code, notes, and snippets.

@CanRau
Forked from pirate/parseURLParameters.js
Created March 20, 2018 20:49
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 CanRau/bda2bdb93700c988d0131b85d017cfd4 to your computer and use it in GitHub Desktop.
Save CanRau/bda2bdb93700c988d0131b85d017cfd4 to your computer and use it in GitHub Desktop.
Parse URL query parameters in ES6
function getUrlParams(search) {
let hashes = search.slice(search.indexOf('?') + 1).split('&')
let params = {}
hashes.map(hash => {
let [key, val] = hash.split('=')
params[key] = decodeURIComponent(val)
})
return params
}
console.log(getUrlParams(window.location.search))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment