Skip to content

Instantly share code, notes, and snippets.

@joshuapbritz
Created November 23, 2017 06:38
Show Gist options
  • Save joshuapbritz/e433b5552c86e98cf21c7f3034253b53 to your computer and use it in GitHub Desktop.
Save joshuapbritz/e433b5552c86e98cf21c7f3034253b53 to your computer and use it in GitHub Desktop.
Decode a Url Query String With JavaScript
function parseQuery(queryString) {
var query = {};
var pairs = (queryString[0] === '?' ? queryString.substr(1) : queryString).split('&');
for (var i = 0; i < pairs.length; i++) {
var pair = pairs[i].split('=');
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
}
return query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment