Skip to content

Instantly share code, notes, and snippets.

@kolodny
Created December 16, 2013 17:17
Show Gist options
  • Save kolodny/7990638 to your computer and use it in GitHub Desktop.
Save kolodny/7990638 to your computer and use it in GitHub Desktop.
Query String Split
console.log(location.search
.substr(1)
.split('&')
.map(function(a) {
return a.split('=');
})
.reduce(function(a,b) {
var arrayProps = /^(.*)\[(\w*)\]$/.exec(b[0]);
if (arrayProps) {
(a[arrayProps[1]] || (a[arrayProps[1]] = []));
if (arrayProps[2]) {
a[arrayProps[1]][arrayProps[2]] = b[1];
} else {
a[arrayProps[1]].push(b[1]);
}
} else {
a[b[0]] = b[1];
}
return a;
}, {})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment