Last active
May 4, 2024 15:38
-
-
Save rendro/525bbbf85e84fa9042c2 to your computer and use it in GitHub Desktop.
Parse document.cookie into object
Rewrite to work on older browsers / js versions:
Object.fromEntries(document.cookie.split(/; */).map(function(c) {
var index = c.indexOf("="); // Find the index of the first equal sign
var key = c.slice(0, index); // Everything upto the index is the key
var value = c.slice(index + 1); // Everything after the index is the value
// Return the key and value
return [ decodeURIComponent(key), decodeURIComponent(value) ];
}));
https://stackoverflow.com/a/64472572/8784402
Object.fromEntries(document.cookie.split('; ').map(v=>v.split(/=(.*)/s).map(decodeURIComponent)))
+1, thanks for the helpful code!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I've been using this: