Created
June 19, 2018 21:02
-
-
Save eljamez/58650a6fc450244f37de2a1e17428763 to your computer and use it in GitHub Desktop.
ES6 friendly function to retrieve url parameters as an Object.
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 getUrlParamsObj = (queryString) => { | |
const paramsArray = (window.location.search.charAt(0) === "?") | |
? window.location.search.substr(1).split('&') | |
: window.location.search.split('&') | |
return paramsArray.reduce((mainObj, val) => { | |
const valArray = val.split('=') | |
return Object.assign(mainObj, {[valArray[0]]: valArray[1]}) | |
}, {}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment