title: Set and Get array from cookies with js-cookie and JSON.parse
body: <p>I'm using js-cookie to store data and get them back, I'm trying to sore an array variable but I have trouble mantaining its format. This is the process that create, retrive, change and save data of the cookie, it works but just the first time, as I'm not able to </p>
  
  <pre><code>// store array in cookie  
  Cookies.set('points', '0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0', { expires: 30 });
  
  // get data from cookie into a variable (becomes a string)  
  points = Cookies.get('points');
  
  // convert to object with (length 12)
  points = JSON.parse("[" + points + "]");
  
  // change value of the array in the varable position
  points[playerId]++;
  
  // save data in cookie
  Cookies.set('points', points, {expires: 30});
  </code></pre>
  
  <p>This works only the first time, any subsequent time I get error and the array become length 1. I'm sure it's because I'm missing squarebrackets but if I try:</p>
  
  <pre><code>Cookies.set('points', '[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]', { expires: 30 });
  </code></pre>
  
  <p>the variable becomes an object with lenght 1 and it does not work.</p>