When looking at location.search, what's the best way to take the query parameters and turn them into an object literal? Say I've got a URL that looks like this:
http://foo.com?nodeId=2&userId=3&sortOrder=name&sequence=asc
What I'd like to wind up with is an object literal that looks like this:
var params = {
nodeId : 2,
userId : 3,
sortOrder: name,
sequence: asc
}
So I'd like to do something like this:
var url = location.search;
url = url.replace('?', '');
var queries = url.split('&');
var params = {};
for(var q in queries) {
var param = queries[q].split('=');
params.param[0] = param[1];
};
But this line:
params.param[0] = param[1]
generates an error. How do you iterate through those keys if you don't know the key names?
We're using jQuery, and I'm sure there's a plugin to do this, but I'd like to understand how to program this anyway.