📝 BLOG.IK.AM

@making's memo
(🗃 Categories 🏷 Tags)

CookieをObjectに変えるJavaScriptワンライナー

🗃 {Programming/JavaScript/Underscore.js}

🗓 Updated at 2014-02-28T07:18:20+09:00 by Toshiaki Maki  🗓 Created at 2014-02-28T07:18:20+09:00 by Toshiaki Maki  {✒️️ Edit  ⏰ History}


☠ Danger: This content is too old. You should avoid reading. If you want to read, please click .

underscore.jsを使えばさくっと書ける。

_.chain(document.cookie.split(';')).map(function(x) {return $.trim(x).split('=')}).object().value()

read onlyだけど。

整形すると

var cookie = _.chain(document.cookie.split(';'))
    .map(function (x) {
        return $.trim(x).split('=')
    })
    .object()
    .value();

こんな感じ。