How to get the value of a cookie in jquery. I want t be able to get the user_first_name
and user_last_name
from this cookie - {"user_first_name":["Raj Subscriber"],"user_last_name":["Chudasama"]}
function getCookieName(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
I tried this:
const userIsLoggedIn = getCookieName('tmm_user_data');
const b = userIsLoggedIn.user_first_name[0];
AND THIS:
const userIsLoggedIn = getCookieName('tmm_user_data');
const b = userIsLoggedIn.user_first_name;
Both return undefined