Created
March 23, 2018 09:17
-
-
Save dominikbulaj/600f5f856c476e650ac8b803c3cbaaf4 to your computer and use it in GitHub Desktop.
Simple code to get URL searchParams as key-value 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
location.search.substr(1) | |
.split('&') | |
.reduce((ac, cur) => { | |
if (cur) { | |
const kv = cur.split('=') | |
ac[kv[0]] = decodeURIComponent(kv[1].replace(/\+/g, ' ')) | |
} | |
return ac | |
}, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment