Skip to content

Instantly share code, notes, and snippets.

@lukasbach
Created May 14, 2018 14:41
Show Gist options
  • Save lukasbach/a6a27a515d2cd4571ef5895f169331be to your computer and use it in GitHub Desktop.
Save lukasbach/a6a27a515d2cd4571ef5895f169331be to your computer and use it in GitHub Desktop.
Get url parameters in JavaScript
const getUrlParams = locationSearch => locationSearch.substring(1).split('&')
.reduce((map, obj) => {let [a, b] = obj.split('='); map[a] = b; return map; }, {});
/*
Example:
const params = getUrlParams(window.location.search);
Assuming window.location.search = ?a=b&c=d
Then: params = {a: 'b', c: 'd'}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment