3

How can I get an array containing names of all cookies starting with word?

0

2 Answers 2

11
document.cookie.split('; ')
    .filter(c => c.startsWith('word'));
Sign up to request clarification or add additional context in comments.

1 Comment

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'));
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.