read cookies with key value pair in JavaScript jquery

read cookies with key value pair in JavaScript jquery

This is basically used to read the cookies data by using the key and value pair in MVC 5 jQuery. The code sample as give below.


var cookies = cookies || {};

cookies.read = new function (){

function setCokiesValue(key, value) {
    session[key] = value;
};

var session = [];

var getCookie = function readCookie() {
       match = document.cookie.match(new RegExp('MyCookieName' + '=([^;]+)'));
       if (match) {
           var array = match[1].split('&');
           for (var i = 0; i < array.length; i++) {
                name = array[i].split('=')[0];
                value = array[i].split('=')[1];
                session.push(setCokiesValue(name, value));
        }
    }
};

return {
       session :session ,
       getCookie :getCookie 
     }
}

ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.