Skip to content

Instantly share code, notes, and snippets.

@jcubic
Last active October 6, 2015 13:58
Show Gist options
  • Save jcubic/3004101 to your computer and use it in GitHub Desktop.
Save jcubic/3004101 to your computer and use it in GitHub Desktop.
create an object from query string
var query = (function() {
function decode(string) {
return decodeURIComponent(string.replace(/\+/g, " "));
}
var result = {};
if (location.search) {
location.search.substring(1).split('&').forEach(function(pair) {
pair = pair.split('=');
result[decode(pair[0])] = decode(pair[1]);
});
}
return result;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment