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: | 1,075 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 94:46:32 |
| Calls: | 13,798 |
| Calls today: | 1 |
| Files: | 186,989 |
| D/L today: |
6,331 files (1,799M bytes) |
| Messages: | 2,438,405 |