Skip to content

Instantly share code, notes, and snippets.

@brookemckim
Created May 1, 2012 18:40
Show Gist options
  • Save brookemckim/2570353 to your computer and use it in GitHub Desktop.
Save brookemckim/2570353 to your computer and use it in GitHub Desktop.
Parse query strings in javascript.
var queryStrings = window.location.search.substring(1).split("&")
var params = {};
for (var i = 0; i < queryStrings.length; i++) {
var splitParam = queryStrings[i].split("=");
if (splitParam.length > 1) {
var key = splitParam[0];
var val = splitParam[1];
params[key] = val;
}
}
@sindresorhus
Copy link

This doesn't handle when a query string doesn't have a value, it should then return null.

See: https://github.com/sindresorhus/query-string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment