Last active
April 25, 2019 08:36
-
-
Save codesorter2015/b5220720802a2e2f1ae5775cd1ea955b to your computer and use it in GitHub Desktop.
Best way to parse query string in JavaScript
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
var parseQuery = ( urlStr ) => { | |
return new URL(urlStr).search.substring(1).split('&').map(i => { let params = {}; let p = i.split('='); params[p[0]] = decodeURIComponent(p[1]); return params }); | |
} | |
console.log(parseQuery("paste your url here")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment