Skip to content

Instantly share code, notes, and snippets.

@kanakiyajay
Created May 26, 2014 08:24
Show Gist options
  • Save kanakiyajay/92b90b99e1273fb5795b to your computer and use it in GitHub Desktop.
Save kanakiyajay/92b90b99e1273fb5795b to your computer and use it in GitHub Desktop.
function getQueryObj (query) {
query = query.substring(query.indexOf("?")+1,query.length);
var keys = query.split("&") , obj = {};
for (var i = 0; i < keys.length; i++) {
var pair = keys[i].split("=");
obj[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
return obj;
}
console.log(getQueryObj("http://example.com?x=hello&y=des%20t"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment