Skip to content

Instantly share code, notes, and snippets.

@biaocy
Created December 9, 2019 09:35
Show Gist options
  • Save biaocy/f376550004bc2a46fe4b079f6c82c01d to your computer and use it in GitHub Desktop.
Save biaocy/f376550004bc2a46fe4b079f6c82c01d to your computer and use it in GitHub Desktop.
Parse query string to object
function getQueryObj(url) {
let re = /[?&]+(\w+)(?:=([\w%\.]*))*/g;
let results, ret = {};
while ((results = re.exec(url)) !== null) {
let [m, k, v] = results; // array destructuring
ret[k] = v;
}
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment