Getting a value from a query string
Instead of splitting from the ?, you can use location.search. It returns everything from (and including) the ? until the end of the query string. If there's a hash, it stops right before #.

Since it includes the ?, you can do location.search.slice(1) to get the string without the ?.

Then you can do:

var queries = location.search
                      .slice(1)
                      .split('&amp;')
                      .reduce(function(carry, query){
                        var queryPair = query.split('=');
                        carry[queryPair[0]] = queryPair[1];
                        return carry;
                      },{});


From ?foo=foovalue&amp;bar=barvalue, you can get something like:

var queries = {
  foo: 'foovalue',
  bar: 'barvalue',
}


I have to add that this only works for 1-level query string. Stuff like arrays (foo[]=foo0&amp;foo[]=foo1) and key-value pairs (foo[bar]=bar&amp;foo[baz]=baz) isn't covered in this logic.