Skip to content

Instantly share code, notes, and snippets.

@antoniocapelo
Last active February 28, 2016 13:27
Show Gist options
  • Save antoniocapelo/6e4f6e3a8236fdcda068 to your computer and use it in GitHub Desktop.
Save antoniocapelo/6e4f6e3a8236fdcda068 to your computer and use it in GitHub Desktop.
Transforming query string params into object
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