How can I get an array containing names of all cookies starting with word?
2 Answers
document.cookie.split('; ')
.filter(c => c.startsWith('word'));
1 Comment
Yann Dìnendal
Both the request Cookie header in nodejs and the client-side
document.cookie are separated by a semi-colon and a space. It should be document.cookie.split('; ').filter(c => c.startsWith('word'));Try this.
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) === ' ') c = c.substring(1);
if (c.indexOf(name) === 0) return c.substring(name.length, c.length);
}
return "";
}
You should then be able to use getCookie(name) and it should return a string containing the cookies. Then just use split on the returned value to get the array. Hope this works for you.