Since cookies are saved all together in a string, you can use methods like split(), find() and startsWith() to get exactly to the cookie key, for example:
const sessionID= document.cookie
.split('; ')
.find(row => row.startsWith('session.ID'))
.split('=')[1];
At the end you will convert the whole string in an array of 2 elements, the key and the value itself, therefore, position [1] in the array.
Another easier way, is to use the npm package doc-cookies. It presents simple methods to set, get and remove cookies, using the syntax:
docCookies.getItem('session.ID')
For setting the cookies in the first place:
docCookies.setItem('session.ID', 'yourCookieValue')
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…