Skip to content

Instantly share code, notes, and snippets.

@jaawerth
Last active November 11, 2015 18:37
Show Gist options
  • Save jaawerth/31ad025e6e55bee85d40 to your computer and use it in GitHub Desktop.
Save jaawerth/31ad025e6e55bee85d40 to your computer and use it in GitHub Desktop.
simple function for parser a URL's querystring into an object of key-value pairs
function parse(qs) {
return qs.replace(/^\?/, '').split('&').reduce(function(col, pairStr) {
// pairStr is of form `foo=bar`
var pair = pairStr.split('=').map(decodeURIComponent);
col[pair[0]] = pair[1];
return col;
}, {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment