Javascript Cookie Reader

javascript cookie reader

Javascript Cookie Reader using pure javascript

Read Cookie from browser using Javascript Cookie Reader. This code is develop using pure Javascript so no need to add any external Javascript library.

* This is generic cookie reader
var cookieReader = function(){
c = document.cookie.split('; ');
cookies = {};
for(i=c.length-1; i>=0; i--)
  C = c[i].split('=');
  cookies[C[0]] = C[1];
return cookies;

* To check the read cookies
* @param {Object} cookieString
var printAllCookies = function(cookieString){
  for(key in cookieString){
    console.log("key : "+ key + " value : " + decodeURIComponent(cookieString[key]));
// decodeURIComponent used to decode the encoded cookie
var cookier = cookieReader();

cookieReader :
The cookieReader() function will read all cookies from your browser and store into an array cookies. And finally return the array.

printAllCookies :
The printAllCookies() function will print all the cookies with key : value p by executing the loop on the cookies array. You can check the results in Javascript Console.

Link : Download Code From Github