Here's an object-oriented way to convert Query Strings into an object. It's an improvement of my previous post How Do I Get Query String Values in JavaScript?

The qsUtil object definition copies window.location.href, i.e. the Query String, into the .qs attribute for later use. Then it parses the this.qs into this.obj when the qsUtil object is constructed. The has(item) method returns true if the Query String has the item in it.

//
// QueryString Util - an object that parses a QueryString into an object.
// .obj - the parameters parsed into an object
// .has(item) - check to see if the item is in the QueryString
//

var qsUtil = function() {
  // simulate a browser query string for testing in Node.js
  if (typeof window === 'undefined') window = {location:{href:"?foo=bar&yes"}};
  this.qs = window.location.href;
  this.obj = {};
  this.has = function(item) {
    return Object.keys(this.obj).indexOf(item) >= 0;
  };
 
  var parms = this.qs.split('?')[1].split('&');
  for(var i in parms) {
    var pair = parms[i].split('=');
    this.obj[pair[0]] = pair[1];
  }
}

This is a test of the qsUtil object. It will return: "foo is there".

function testQsUtil() {
 var qsUtilObj = new qsUtil();
 var item = 'foo';
 return (item + " is " + (qsUtilObj.has(item) ? "is" : "not") + " there");
}