Convert POST/GET queries to object in JS

A handy JS string prototype function for converting POST/GET queries to objects.

String.prototype.toURLobject = function() 
{
	var query = decodeURIComponent(this);
	var parts = query.split("&");
	var obj = {};
	for(var i = 0; i < parts.length; i++)
	{
		var pair = parts[i].split("=");
		var index = pair[0].indexOf("[]");
		if (index != -1)
		{
			var name = pair[0].substr(0, index);
			if (!obj.hasOwnProperty(name))
			{
				obj[name] = [];
				obj[name].push(pair[1]);
			}
			else
				obj[name].push(pair[1]);
		}
		else
			obj[pair[0]] = pair[1];
	}

	return obj;
}