Skip to content

Instantly share code, notes, and snippets.

@fogmoon
Forked from pirate/parseURLParameters.js
Created September 11, 2018 06:35
Show Gist options
  • Save fogmoon/db1329778524da75ea0269e103dcf3b2 to your computer and use it in GitHub Desktop.
Save fogmoon/db1329778524da75ea0269e103dcf3b2 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