Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
querrystring to object
/**
* converts querystring to object. Allows multiple values per key
* @param {String} querystring - optional querystring. default address bar
* @return {object}
*/
self.querystringToObject = function(querystring){
var params = {};
(querystring || window.location.search)
.replace(/([^?=&]+)(=([^&]*))?/g, function($0, $1, $2, $3) {
if (params[$1]){
if (!$.isArray(params[$1])){
params[$1] = [params[$1]];
}
params[$1].push($3);
}else{
params[$1] = $3;
}
});
return params;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment