Show All Cookies using JavaScript language

  1. /* 
  2. * return all cookies with array.
  3. */  
  4. function get_cookies_array() {  
  5.     var cookies = { }; 
  6.     // if document.cookie not null or empty
  7.     if (document.cookie && document.cookie != '') {  
  8.         var split = document.cookie.split(';');  
  9.         for (var i = 0; i < split.length; i++) {  
  10.             var name_value = split[i].split("=");  
  11.             name_value[0] = name_value[0].replace(/^ /, '');  
  12.             cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);  
  13.         }  
  14.     }  
  15.     return cookies;   

Example:
  1. /* 
  2. * read & show cookies name and value with loop from get_cookies_array() method.
  3. */  
  4. var cookies = get_cookies_array();  
  5. for(var name in cookies) { alert( name + " : " + cookies[name] + "" ); }