Created
November 23, 2017 06:38
-
-
Save joshuapbritz/e433b5552c86e98cf21c7f3034253b53 to your computer and use it in GitHub Desktop.
Decode a Url Query String With JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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