Skip to content

Instantly share code, notes, and snippets.

@amit-y
Created May 26, 2015 19:19
Show Gist options
  • Save amit-y/58d56b1797b2773c084b to your computer and use it in GitHub Desktop.
Save amit-y/58d56b1797b2773c084b to your computer and use it in GitHub Desktop.
Query string as an object
var queryStringToObj = function() {
var qs = location.search.substr(1).split(/&/);
var q = {};
for (var i=0; i<qs.length; i+=1) {
var queryVar = qs[i].split('=');
var key = decodeURIComponent(queryVar[0]);
var val = (queryVar[1] === undefined) ? null : decodeURIComponent(queryVar[1]);
q[key] = val;
}
return q;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment