title: How do I stringify an array of objects?
body: <p>I have created an array of objects that needs to be stored and kept for another page.</p>
  
  <p>The array of objects is similar to this:</p>
  
  <pre><code>var cheese_array = [
    {
      name: "Chedder",
      age: "34",
      smelly: true
    },
    {
      name: "Brie",
      age: "4",
      smelly: false
    },
    {
      name: "Blue Stilton",
      age: "13",
      smelly: true
    }
   ];
  </code></pre>
  
  <p>But when I <code>JSON.stringify()</code> it, it doesn't stringify the objects, only the array. So I end up with and array that looks like this:</p>
  
  <pre><code>[object Object], [object Object], [object Object]
  </code></pre>
  
  <p>So how do you stringify these objects in this array.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong>
  This array of objects is then passed to an on click function similar to this:</p>
  
  <pre><code>$("#a-button").click(function() {
    var cheese_arr_stringify = JSON.stringify(cheese_array);
    sessionStorage.cheeseArray = cheese_arr_stringify;
    if(sessionStorage.cheeseArray) {
      window.location.href = "../";
    }
   });
  </code></pre>
  
  <p>So pretty much, its sets <code>cheese_arr_stringify</code> to a stringified version of the array of objects. Then it sets this stringified code to a session key. Following this, once it has been set cheeseArray it send it up one directory.</p>
  
  <p><hr>
  <strong>EDIT 2:</strong>
  This is an image of the session key after being stringified. In this case, foodItems is the same as cheeseArray</p>
  
  <p><a href="https://i.stack.imgur.com/LXqAc.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LXqAc.png" alt="Session Storage"></a></p>
  
  <p><hr>
  <strong>EDIT 3:</strong>
  @Rayon asked for a fiddle so he could have a look, I made it up and it had worked. The problem was - I feel so stupid now - that I was calling the array instead of the stringified var I had made.</p>