Get List of All Cookies Using Javascript

Get List of All Cookies Using Javascript

Its very common that we all still use HTTP Cookies Using Javascript  for storing various data on visitor’s browser. But in HTML5,and other website languages you can use local storage. I’m talking about the old school Cookies Using Javascript here as we still have old browsers to take care Cookies Using Javascript. Following is the code snippet to log all Cookies Using Javascript of the domain in the firebug console.

Get List of All Cookies Using Javascript

function get_cookies_array() {

    var cookies = { };

    if (document.cookie && document.cookie != '') {
        var split = document.cookie.split(';');
        for (var i = 0; i < split.length; i++) {
            var name_value = split[i].split("=");
            name_value[0] = name_value[0].replace(/^ /, '');
            cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
        }
    }

    return cookies;
   
}
var cookies = get_cookies_array();
for(var name in cookies) {
 console.log( name + " : " + cookies[name] + "
" );
}