Skip to content

Instantly share code, notes, and snippets.

@pzzrudlf
Created January 6, 2016 13:10
Show Gist options
  • Select an option

  • Save pzzrudlf/3064fbf2355cd89a3519 to your computer and use it in GitHub Desktop.

Select an option

Save pzzrudlf/3064fbf2355cd89a3519 to your computer and use it in GitHub Desktop.
function parseQuery(query){
var args = {};
var items = query.split("&");
var item = null, name = null, value = null;
for(var i=0; i < items.length; i++){
item = items[i].split("=");
if(item[0]){
name = item[0];
value = item[1] ? item[1] : "";
args[name] = value;
}
}
return args;
}
function parseQuery(str){
return str.split('&').reduce((memo, x) => {
let qa = x.split('=');
if(!qa[0]) return memo;
return Object.assign(memo, {
[qa[0]]: qa[1]?qa[1]:""
})
}, {})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment