Skip to content

Instantly share code, notes, and snippets.

@codesorter2015
Last active April 25, 2019 08:36
Show Gist options
  • Save codesorter2015/b5220720802a2e2f1ae5775cd1ea955b to your computer and use it in GitHub Desktop.
Save codesorter2015/b5220720802a2e2f1ae5775cd1ea955b to your computer and use it in GitHub Desktop.
Best way to parse query string in JavaScript
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