title: How to use for loop with obj?
body: <p>I have this:</p>
  
  <pre><code>Alabama:
  data: (28) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
  lat: "32.3182"
  long: "-86.9023"
  state: "Alabama"
  __proto__: Object
  Alaska: {state: "Alaska", lat: "61.3707", long: "-152.4044", data: Array(28)}
  Alberta: {state: "Alberta", lat: "53.9333", long: "-116.5765", data: Array(2)}
  </code></pre>
  
  <p>So for each state we have soem values and <code>data</code> with values in it. One of the value inside that is <code>date</code></p>
  
  <p>I need to loop that to push to array</p>
  
  <pre><code>var dataSetCopy = [];
  for(var t = 0; t &lt; initialDataSet.length; ++t) {
      var eachStateData = initialDataSet[t].data;
      // this is not working &gt; console.log(eachStateData);
      dataSetCopy.push(eachStateData.date);
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const formatted = data.reduce((merged, entry) =&gt; {
      const {
          // These properties will show up only once per state:
          lat,
          long,
          Province_State: state,
          // Anything else is grouped inside the `data` field for this state's entry:
          ...rest
      } = entry;
  
      // You can modify the `date` field here:
      rest.date = rest.date.split(' ')[0];
  
      if (merged.hasOwnProperty(state)) {
          // If we already added an entry for this state, simply push the other properties to `data`:
          merged[state].data.push(rest);
      } else {
          // Otherwise, add the entry for this state:
          merged[state] = { state, lat, long, data: [rest] };
      }  
  
      return merged;  
      }, { });
  
  initUI(formatted);
  
  function initUI(initialDataSet) {
  
      const dataSetCopy = [];
      initialDataSet.forEach(item =&gt; {
          const data = item.data; 
          data.forEach(obj =&gt; {
              dataSetCopy.push(obj.date)
          }) 
      });
  
      console.log(dataSetCopy);
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://jikuhealth.com/wp-content/themes/JikuHealth/demo_js/united_states/5-11-20_us_states.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>