Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what mean .length in document.cookie

Can I ask what mean document.cookie.length in javascript? the number of cookies in document.cookie object Thanks! This is the code:

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
like image 475
dramasea Avatar asked Mar 06 '26 05:03

dramasea


1 Answers

document.cookie is simply a string, so .length is the length of that string. JavaScript doesn't provide any built-in functions to parse the individual cookies, you have to do that yourself.

like image 187
casablanca Avatar answered Mar 07 '26 18:03

casablanca



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!