Skip to content

Instantly share code, notes, and snippets.

@johnbeech
Created November 20, 2018 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbeech/9e233794eaf0b77a16fb50671f72ebd4 to your computer and use it in GitHub Desktop.
Save johnbeech/9e233794eaf0b77a16fb50671f72ebd4 to your computer and use it in GitHub Desktop.
Parse parameters from URL
// collapsed onto one line
const getParams(href) => (href.split('?')[1] || '').split('&').map(kvp => kvp.split('=')).reduce((acc, kvp) => { acc[kvp[0]] = kvp[1]; return acc }, {})
// spread out into a traditional function
function getParams(href) {
return (href.split('?')[1] || '')
.split('&')
.map(kvp => kvp.split('='))
.reduce((acc, kvp) => {
acc[kvp[0]] = kvp[1];
return acc
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment