Skip to content

Instantly share code, notes, and snippets.

@Hafthor
Created April 9, 2015 23:19
Show Gist options
  • Save Hafthor/11298ce2480baecf03ad to your computer and use it in GitHub Desktop.
Save Hafthor/11298ce2480baecf03ad to your computer and use it in GitHub Desktop.
parse query string into handy map
function searchmap(separator) {
var map = {};
(location.search || '')
.split("&")
.forEach(function(x) {
var kv = x.split('='), k = kv[0], v = decodeURIComponent(x.substr(k + 1));
if (separator === undefined)
if (map[k])
map[k] = [v];
else
map[k].push(v);
else
map[k] = map[k] ? map[k] + separator + v : v;
});
return map;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment