Skip to content

Instantly share code, notes, and snippets.

@ahsquared
Last active May 19, 2020 18:18
Show Gist options
  • Save ahsquared/ea12db0011ae897f85ec2de4e872b132 to your computer and use it in GitHub Desktop.
Save ahsquared/ea12db0011ae897f85ec2de4e872b132 to your computer and use it in GitHub Desktop.
Quick way to get query params in ES6
qp =()=> window.location.search.substr(1).split('&').reduce( (a, c) => Object.assign(a, (c.indexOf('=') !== -1 ? c : `${c}=`).split('=').reduce( (a, c) => ({[a]: c})) ) ,{})
@ahsquared
Copy link
Author

This now handles query params with no value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment