Home > Mobile >  Use of indexOf() method in javascript cookies?
Use of indexOf() method in javascript cookies?

Time:07-14

cstart = document.cookie.indexOf(cname "="); What is the use of "=" after cname in the above method ?

CodePudding user response:

Here cname seems to be a variable and with it is contacting the variable and =.

So if const cname='someName', the the code

cstart = document.cookie.indexOf(cname "=") will compile to

cstart = document.cookie.indexOf("someName=")

CodePudding user response:

It is searching the cookie index. Like a=b If you only search for a it you may get the wrong result in

c=abc&a=b.

Because It will result the first a in c=a (<= here) bc

So add a = to make it search correctly.

  • Related