title: creating an multidimensional Object dynamically from an multidimensional array
body: <p>Im trying to create an multidimensional Object like this one:</p>
  <pre><code>{ A : {a1: {},a2:{}}, B: {b1:{},b2:{}}}
  </code></pre>
  <p>from an multidimensional array like this one:</p>
  <pre><code>let array1 = [
        ['A', 'a1'],
        ['A', 'a1'],
        ['A', 'a2'],
        ['B', 'b1'],
        ['B', 'b1'],
        ['B', 'b2'],
      ];
  </code></pre>
  <p>I'm trying this for some hours now and was also reading plenty of entrys here on stackoverflow, but nothing really fits this specific case.</p>
  <p>What i did so far:</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>    let array1 = [
        ['A', 'a1'],
        ['A', 'a1'],
        ['A', 'a2'],
        ['B', 'b1'],
        ['B', 'b1'],
        ['B', 'b2'],
      ];
  
      let object1 = {};
  
      array1.forEach(function (subArray) {
        let level1 = subArray[0];
        let level2 = subArray[1];
  
        object1[[level1]] = { ...{ [level2]: {} } };
      });
  
      console.log('object: ', object1);
      //desired output:  object = { A : {a1: {},a2:{}}, B: {b1:{},b2:{}}}
      //what I get:  object = { A : {a2:{}}, B: {b2:{}}}</code></pre>
  </div>
  </div>
  </p>
  <p>So somehow in my code the entrys like {a1: {}} are getting overwritten in each iteration instead of adding a new entry.</p>
  <p>Thanks a lot in advance.</p>