How do I create and read a value from cookie in JavaScript?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
Minimalistic and full featured ES6 approach:
Here are functions you can use for creating and retrieving cookies.
Simple way to read cookies in ES6.
An improved version of the readCookie:
This should break as soon as you have found your cookie value and return its value. In my opinion very elegant with the double split.
The replace on the if-condition is a white space trim, to make sure it matches correctly