Created
December 9, 2019 09:35
-
-
Save biaocy/f376550004bc2a46fe4b079f6c82c01d to your computer and use it in GitHub Desktop.
Parse query string to object
This file contains hidden or 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 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