Skip to content

Instantly share code, notes, and snippets.

Last active Dec 22, 2015
What would you like to do?
Javascript - URL Params Anonymous function Object
var urlParams = {};
(function() {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query =;
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
//Usage urlParams['q'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment