Very simple cookie reader

If you want to read cookies in javascript (browser) without any library, that’s the easiest function you can use:

var cookies = {};
document.cookie.split(";").forEach(c => {
	c = c.trim().split("=");
	cookies[c[0]] = c.length > 1 ? c[1] : "";
var userCookie = cookies.user;

That’s it !

Happy coding.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.