I'm currently working on a project that already has several cookies stored. My goal is to determine if the cookie labeled "login" exists. Below is the code snippet I am using:
if (document.cookie.indexOf("login") >= 0) {
alert("login cookie exists");
}
else if(document.cookie.indexOf("login") < 0 ){
alert("no login cookie");
}
else{
}
However, there seems to be an issue with my code. The indexOf
method should return -1 or 0 based on whether the cookie exists, right? Surprisingly, in both cases it's returning -1. Could it be a problem with my if
statement?