Created
December 30, 2022 17:47
-
-
Save benergize/fd54cb16f9ecdf7243dd712db2238b87 to your computer and use it in GitHub Desktop.
Get variables to JS 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
$_GET = (function() { | |
let x = {}; | |
(decodeURI(window.location.search).replace("?","").split("&")||[]).forEach(el=>{ | |
let ab = el.split("="); | |
if(ab[0].slice(-2) == "[]") { | |
ab[0]=ab[0].replace("[]",""); | |
if(!Array.isArray(x[ab[0]])){ x[ab[0]] = []; } | |
x[ab[0]].push(ab[1]); | |
} | |
else { x[ab[0]] = ab[1] } | |
}); | |
return x; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment