Created
November 20, 2018 13:10
-
-
Save johnbeech/9e233794eaf0b77a16fb50671f72ebd4 to your computer and use it in GitHub Desktop.
Parse parameters from URL
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
// 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