Skip to content

Instantly share code, notes, and snippets.

@eljamez
Created June 19, 2018 21:02
Show Gist options
  • Save eljamez/58650a6fc450244f37de2a1e17428763 to your computer and use it in GitHub Desktop.
Save eljamez/58650a6fc450244f37de2a1e17428763 to your computer and use it in GitHub Desktop.
ES6 friendly function to retrieve url parameters as an Object.
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