Last active
December 24, 2020 15:57
-
-
Save moesoha/b36e5846226e4c15a5bed76a01e2ced9 to your computer and use it in GitHub Desktop.
Get SearchParams
This file contains 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
// compatibility: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/fromEntries | |
const getQueryParams = s => Object.fromEntries(s.split('&').map(s => s.split('=')).map(a => [a.shift(), a.join('=')].map(s => decodeURIComponent(s || ''))).filter(([k, _]) => k.length > 0)); | |
// window.$_GET = getQueryParams(window.location.search.slice(1)); |
This file contains 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
function getQueryParams(search) { | |
var params = {}; | |
search | |
.split('&') | |
.map(function (s) { return s.split('='); }) | |
.map(function (a) { return [a.shift(), a.join('=')].map(function (s) { return decodeURIComponent(s || ''); }); }) | |
.filter(function (a) { return a[0].length > 0; }) | |
.forEach(function (a) { params[a[0]] = a[1]; }) | |
; | |
return params; | |
} | |
// window.$_GET = getQueryParams(window.location.search.slice(1)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment