Skip to main content
Home / Code Snippets / jQuery Code Snippets / Get Query Params as Object

Get Query Params as Object

Nicholas Ortenzio wrote this little plugin:


  getQueryParameters : function(str) {
	  return (str ||^\?)/,'').split("&").map(function(n){return n = n.split("="),this[n[0]] = n[1],this}.bind({}))[0];


So if the URL is:

You can do:

var queryParams = $.getQueryParameters();

And queryParams will be an object like:

   "lunch": "sandwich",
   "dinner": "stirfry"