Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Return an object model of a URI query (search or hash)
/* Return an object model of a URI query (search or hash) */
function uriQueryObj(str){
if(!str) return false;
var str = decodeURIComponent(str),
str = /(^#)|(^$)/.test(str) ? str.substr(1) : str,
arr = str.substr(1).split('&'),
hash = {};
while(arr.length && arr[0]){
var bits = arr.pop().split('=')
hash[bits[0]] = bits[1] || bits[0];
}
return hash;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment