Skip to content

Instantly share code, notes, and snippets.

@hampusn
Last active September 29, 2017 12:17
Show Gist options
  • Save hampusn/d10aa8008e469381124125063cf641a6 to your computer and use it in GitHub Desktop.
Save hampusn/d10aa8008e469381124125063cf641a6 to your computer and use it in GitHub Desktop.
Get query parameters as literal object.
// Get query parameters as literal object.
var queryObject = (function (queryParams, k, v) {
return queryParams.reduce(function (params, p) {
if ((p = p.split('=')).length) {
k = p[0];
v = p[0];
params[k] = (typeof params[k] !== 'undefined') ? (Array.isArray(params[k]) ? params[k] : [params[k]]).concat(v) : v;
}
return params;
}, {});
})(window.location.search.slice(1).split('&'));
var queryObject=function(r,n,t){return r.reduce(function(r,c){return(c=c.split("=")).length&&(n=c[0],t=c[0],r[n]=void 0!==r[n]?(Array.isArray(r[n])?r[n]:[r[n]]).concat(t):t),r},{})}(window.location.search.slice(1).split("&"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment