Skip to content

Instantly share code, notes, and snippets.

@SapientBoston
Created November 13, 2012 00:28
Show Gist options
  • Select an option

  • Save SapientBoston/4063012 to your computer and use it in GitHub Desktop.

Select an option

Save SapientBoston/4063012 to your computer and use it in GitHub Desktop.
JavaScript: Query String Map
var queryStringMap = (function(){
'use strict';
var obj = {},
params = location.search.replace(/^\?/,'').split('&'),
i, param, key;
for(i = params.length - 1; i >= 0; i--){
param = params[i].split('=');
key = param[0];
if(key){
obj[key] = param[1];
}
}
return obj;
}());
/* Example Usage
if(queryStringMap.testParam){
console.log("testParam is in the query string, and its value is: ", queryStringMap.testParam);
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment