title: Convert arrays to nested objects javascript
body: <p>I have a array of objects, like this:</p>
  
  <pre><code>var tryArray = [{
    name: 'name1',
    subname: 'subname1',
    symbolname: 'symbol1'
  },
  {
    name: 'name1',
    subname: 'subname11',
    symbolname: 'symbol11'
  },
  {
    name: 'name2',
    subname: 'subname2',
    symbolname: 'symbol2'
  },
  {
    name: 'name2',
    subname: 'subname22',
    symbolname: 'symbol22'
  },
  {
    name: 'name3',
    subname: 'subname3',
    symbolname: 'symbol3'
  },
  {
    name: 'name3',
    subname: 'subname33',
    symbolname: 'symbol33'
  }];
  </code></pre>
  
  <p>I want to convert this array into a nested object, where the name will be parent of subname, and subname will be parent of symbolname. For example:</p>
  
  <pre><code>result = {
    name1: {
      subname1: [symbolname1],
      subname11: [symbolname11] 
    },
    name2: {
      subname2: [symbolname2],
      subname22: [symbolname22] 
    },
    name3: {
      subname3: [symbolname3],
      subname33: [symbolname33] 
    }
  }
  </code></pre>
  
  <p>I have tried using reduce like this</p>
  
  <pre><code>tryArray.reduce((object, item) =&gt; {
     object[item.name] = {[item.subname]: [item.symbolname]}
  },{})
  </code></pre>
  
  <p>but it returned only one subname. any ideas how to resolved this, thank you so much </p>