title: initialize array that is within a object, use in localStorage
body: <p><strong>Isolated Question:</strong></p>
  
  <pre><code>user[username] = { 
    cool: true,
    stuff: false,
    arrData: []
  };
  </code></pre>
  
  <p>I am trying to globally initialize my arrData array in order to populate in different scope; the below does not work.</p>
  
  <pre><code>let user.arrData = [],
  </code></pre>
  
  <p>later I want to do the following, for context:</p>
  
  <pre><code>...........
    inputs.forEach(function(input){
        user = JSON.parse(localStorage.getItem(username)); // tried moving this here
        user.arrData.push({ id: input.id, checked: input.checked });
        // the above errors on .arrData cannot push undefined, I have tried also including the key here, how is this done?
    });
    localStorage.setItem(user, JSON.stringify(user.arrData));
    console.log({ arrData: user.arrData }); // returns undefined
  ............
  </code></pre>
  
  <p><strong>Sub question:</strong> can I set and retrieve a object.array with <code>localStorage</code> like this. Meaning my reference to <code>(user.arrData)</code>?</p>
  
  <hr>
  
  <p>Context/actual code:</p>
  
  <p><strong>Below is the complete relevant code for context: I am trying to save a series of checkbox states per user with local storage, then reload them when a button is clicked.</strong></p>
  
  <pre><code>let user = {};
  var savebtnBM = document.getElementById("savebtnBM");
  const username = document.querySelector("span.name").textContent;
  
  user[username] = { 
     cool: true,
     stuff: false,
     arrData: []
  };
  
  var layersMod =  document.querySelectorAll(".layers #savebtnBM")[0];
  layersMod.addEventListener('click', ()=&gt;{ 
  setTimeout(
    function() {
      Saver();
    }, 2000);
  });
  
  function Saver() { 
    var inputs = document.querySelectorAll('input[type="checkbox"]');
    // var arrData = [];
    inputs.forEach(function(input){
      user[username].arrData.push({ id: input.id, checked: input.checked });
    });
    localStorage.setItem(user, JSON.stringify(user.arrData));
    console.log(JSON.stringify(user.arrData));
  }
  
  var etHOME= document.getElementById("et-phone-home");
  etHOME.addEventListener('click', ()=&gt;{
      user = JSON.parse(localStorage.getItem(username));
      console.log(user);
      document.getElementsByClassName("big-button")[0].click();
      setTimeout(load_, 2000);
  
      function load_() {
        var inputs = JSON.parse(localStorage.getItem(user));
        inputs.forEach(function(input){
          document.getElementById(input.id).checked = input.checked;
          load__();
        });
      function load__() { 
          var elems = document.querySelectorAll('input:checked');
          for(var i = 0; i&lt;elems.length; i++) {
            elems[i].click();
          }
        }
      } 
  });
  </code></pre>