-
-
Save CanRau/bda2bdb93700c988d0131b85d017cfd4 to your computer and use it in GitHub Desktop.
Parse URL query parameters in ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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