Skip to content

Instantly share code, notes, and snippets.

@kynatro
Created September 29, 2014 17:23
Show Gist options
  • Save kynatro/f73eaf3b9444bcda64b4 to your computer and use it in GitHub Desktop.
Save kynatro/f73eaf3b9444bcda64b4 to your computer and use it in GitHub Desktop.
Cookies as an Object (Major modern browsers and IE9+)
document.cookie.split("; ").map(function(i){
return i.split("=");
}).reduce(function(o, v, i){
try {
o[v[0]] = JSON.parse(decodeURIComponent(v[1]));
} catch(e) {
o[v[0]] = decodeURIComponent(v[1]);
}
return o;
}, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment