Get Cookie by Specific Name
In your code, you have a getter that retrieves values from all cookies and splits them into an array. You want to modify it to retrieve values only from a specific cookie named "obligations=".
Solution:
To achieve this, you can use the following approach:
function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); }
Walkthrough:
The above is the detailed content of How Can I Retrieve a Specific Cookie's Value by Name in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!