How to set variable in JSON cookie?
<p>I'm using <strong>js.cookie.js</strong> <a href="https://github.com/js-cookie/js-cookie" rel="nofollow">Github</a> and trying to set a JSON cookie.
In documentation of <strong>js.cookie.js</strong> mentioned that if you want set a JSON cookie you must do like this:</p>

<pre><code>Cookies.set('name', { foo: 'bar' });
</code></pre>

<p>so the cookie data will be like below if you call <code>Cookies.getJSON('name');</code>:</p>

<pre><code>{ foo: 'bar' }
</code></pre>

<p>Now my question is how to set <code>foo</code> from a javascript variable. I tried this but was not useful:</p>

<pre><code>var myVar = 'foo';
Cookies.set('name', { myVar: 'bar' });
</code></pre>

<p>the result was <code>{ myVar: 'bar' }</code> and not <code>{ foo: 'bar' }</code></p>

<p>My JSFIDDLE.COM test: <a href="https://jsfiddle.net/nz2ur613/" rel="nofollow">https://jsfiddle.net/nz2ur613/</a></p>