Skip to content

Instantly share code, notes, and snippets.

@chrisbloom7
Created December 14, 2012 15:28
Show Gist options
  • Save chrisbloom7/4286262 to your computer and use it in GitHub Desktop.
Save chrisbloom7/4286262 to your computer and use it in GitHub Desktop.
Split a query string into key/value pairs in JavaScript
var q = {}; window.location.search.replace(/^\?/, '').split('&').map(function(e){
var a = e.split('=');
q[a[0]] = a[1];
});
for (a in q) { console.log(a, q[a]); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment