How do I create and read a value from cookie?

前端 未结 19 1636
梦如初夏
梦如初夏 2020-11-21 04:42

How can I create and read a value from a cookie in JavaScript?

19条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 05:01

    Simple way to read cookies in ES6.

    function getCookies() {
        var cookies = {};
        for (let cookie of document.cookie.split('; ')) {
            let [name, value] = cookie.split("=");
            cookies[name] = decodeURIComponent(value);
        }
        console.dir(cookies);
    }
    

提交回复
热议问题