Skip to content

Instantly share code, notes, and snippets.

@benergize
Created December 30, 2022 17:47
Show Gist options
  • Save benergize/fd54cb16f9ecdf7243dd712db2238b87 to your computer and use it in GitHub Desktop.
Save benergize/fd54cb16f9ecdf7243dd712db2238b87 to your computer and use it in GitHub Desktop.
Get variables to JS object
$_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