Created
July 22, 2018 14:47
-
-
Save giovanigenerali/7b9103f821c82ca6fc44ebe84e883e60 to your computer and use it in GitHub Desktop.
getParamsFromURL
This file contains 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
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¶m2=value2'); | |
console.log(params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment