Created
May 14, 2018 14:41
-
-
Save lukasbach/a6a27a515d2cd4571ef5895f169331be to your computer and use it in GitHub Desktop.
Get url parameters in JavaScript
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
const getUrlParams = locationSearch => locationSearch.substring(1).split('&') | |
.reduce((map, obj) => {let [a, b] = obj.split('='); map[a] = b; return map; }, {}); | |
/* | |
Example: | |
const params = getUrlParams(window.location.search); | |
Assuming window.location.search = ?a=b&c=d | |
Then: params = {a: 'b', c: 'd'} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment