Skip to content

Instantly share code, notes, and snippets.

@dimosr
Created June 15, 2016 13:59
Show Gist options
  • Save dimosr/264de40320361ee81b27c6c228a24031 to your computer and use it in GitHub Desktop.
Save dimosr/264de40320361ee81b27c6c228a24031 to your computer and use it in GitHub Desktop.
Function parsing the cookies string from the browser & creating a HashMap of cookies keys-values
function getCookiesMap(cookiesString) {
return cookiesString.split(";")
.map(function(cookieString) {
return cookieString.trim().split("=");
})
.reduce(function(acc, curr) {
acc[curr[0]] = curr[1];
return acc;
}, {});
}
//Example Usage
getCookiesMap(document.cookie);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment