Last active
February 28, 2016 13:27
-
-
Save antoniocapelo/6e4f6e3a8236fdcda068 to your computer and use it in GitHub Desktop.
Transforming query string params into object
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
function getParamsObj(url) { | |
return url | |
.split('?')[1] | |
.split('&') | |
.map(function(el) { | |
return el.split('='); | |
}) | |
.reduce(function(prevVal, currVal) { | |
prevVal[currVal[0]] = currVal[1] | |
.split(',') | |
.filter(function(el){ | |
return el.length>0; | |
}); | |
return prevVal; | |
},{} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment