title: How to store array in jQuery cookie?
body: <p>I'm opening a new thread based on this <a href="https://stackoverflow.com/questions/1959455/how-to-store-an-array-in-jquery-cookie">how to store an array in jquery cookie?</a>. I'm using function from almog.ori :</p>
  
  <pre><code>var cookieList = function(cookieName) {
  //When the cookie is saved the items will be a comma seperated string
  //So we will split the cookie by comma to get the original array
  var cookie = $.cookie(cookieName);
  //Load the items or a new array if null.
  var items = cookie ? cookie.split(/,/) : new Array();
  
  //Return a object that we can use to access the array.
  //while hiding direct access to the declared items array
  //this is called closures see http://www.jibbering.com/faq/faq_notes/closures.html
  return {
      "add": function(val) {
          //Add to the items.
          items.push(val);
          //Save the items to a cookie.
          $.cookie(cookieName, items);
      },
      "clear": function() {
          //clear the cookie.
          $.cookie(cookieName, null);
      },
      "items": function() {
          //Get all the items.
          return items;
      }
    }
  }
  </code></pre>
  
  <p>to grab an array of index element on click event :</p>
  
  <pre><code>var list = new cookieList("test");
  $(img).one('click', function(i){
  while($('.selected').length &lt; 3) {
      $(this).parent()
          .addClass("selected")
          .append(setup.config.overlay);
  
      //$.cookie(setup.config.COOKIE_NAME, d, setup.config.OPTS);
      var index = $(this).parent().index();
  
      // suppose this array go into cookies.. but failed
      list.add( index );
      // this index goes in array
      alert(list.items());
  
      var count = 'You have selected : &lt;span&gt;' + $('.selected').length + '&lt;/span&gt; deals';
      if( $('.total').length ){
          $('.total').html(count);
      }
  
  } 
  });
  </code></pre>
  
  <p>When I getting list of items, it return null but when I alert in onclick event, eventually it push value into that array. But when I'd tried to retrieve back cookie, it return null. Help please...</p>