title: LocalStorage save and load JS Object
body: <p>I'm trying to save an array consisting of multiple JS objects via localStorage.</p>
  
  <p>I guess I'm having the same trouble as <a href="https://stackoverflow.com/questions/41863576/fail-when-pushing-an-array-of-js-objects-to-localstorage-and-then-retrieving-it">Fail when pushing an array of js objects to localStorage and then retrieving it and parsing</a>, but there's no solution to it.</p>
  
  <pre><code>var featureArray=[];
  map.on('click', function(evt) {
    if (feature) {
      featureArray.push(feature.values_);
    }
  });
  
  function saveFeatures() {
    localStorage.setItem('features', featureArray);
  }
  saveFeatures();
  </code></pre>
  
  <p>when I try to load them via <code>localStorage.getItem('features')</code> the output is something like:</p>
  
  <blockquote>
    <p>[object Object],[object Object]</p>
  </blockquote>
  
  <p>But I actually want the values behind this structure to be saved.</p>
  
  <p>I tried <code>localStorage.setItem('features', JSON.stringify(featureArray))</code> , but that throws the error</p>
  
  <blockquote>
    <p>TypeError: Converting circular structure to JSON</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <p>console.log(featureArray)'s output:</p>
  
  <pre><code>(2) [{…}, {…}]
  0:
      geometry:ol.geom.MultiPolygon {pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_: 2, ol_uid: 39, …}
      krs:"Niedersachsen"
      sumarea_1_2014:20298
      sumarea_1_2015:16045
      sumarea_1_2016:19008
      sumarea_3_2014:3888
      sumarea_3_2015:27971
      sumarea_3_2016:15520
      sumarea_5_2014:11888
      sumarea_5_2015:14671
      sumarea_5_2016:31307
      __proto__:Object
  1:
      geometry:ol.geom.MultiPolygon {pendingRemovals_: {…}, dispatching_: {…}, listeners_: {…}, revision_: 2, ol_uid: 41, …}
      krs:"Nordrhein-Westfalen"
      sumarea_1_2014:23100
      sumarea_1_2015:2399
      sumarea_1_2016:21916
      sumarea_3_2014:11375
      sumarea_3_2015:31563
      sumarea_3_2016:20300
      sumarea_5_2014:859
      sumarea_5_2015:20633
      sumarea_5_2016:31101
      __proto__:Object
  length:2
  __proto__:Array(0)
  </code></pre>
  
  <p><strong>UPDATE: <a href="https://jsfiddle.net/ytc26fju/3/" rel="nofollow noreferrer">https://jsfiddle.net/ytc26fju/3/</a></strong> . hover over the dot to update the array. then click save and then the load button.</p>