I was trying to check whether a cookie is set to a particular value or not (on the client side, in JS), and found this code on MDN:
if (document.cookie.split(';').filter((item) => item.includes('reader=1')).length) {
console.log('The cookie "reader" has "1" for value')
}
What I'd like to know is - what's the ".length" at the end for? I'm trying to get the VALUE of the cookie, why would it's *length* be required?
I was trying to check whether a cookie is set to a particular value or
not (on the client side, in JS), and found this code on MDN:
if (document.cookie.split(';').filter(
(item) => item.includes('reader=1')).length) {
console.log('The cookie "reader" has "1" for value')
}
What I'd like to know is - what's the ".length" at the end for? I'm
trying to get the VALUE of the cookie, why would it's *length* be
required?
The original code (which you altered) is intended to find out if a key exists, not what value it has.
On Wednesday, 21 November 2018 18:07:55 UTC+5:30, Ben Bacarisse wrote:
The original code (which you altered) is intended to find out if a key
exists, not what value it has.
I did not! This page, look at Example 6 (I have a feeling you were
looking at 5!):
https://developer.mozilla.org/en-US/docs/Web/API/document/cookie--
I was trying to check whether a cookie is set to a particular value or not (on the client side, in JS), and found this code on MDN:
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 994 |
Nodes: | 10 (0 / 10) |
Uptime: | 97:26:48 |
Calls: | 13,016 |
Calls today: | 2 |
Files: | 186,574 |
Messages: | 3,282,099 |