title: Arrange JSON in tree structure
body: <p>I have a plain JSON that contasins the id's of its dependentant's objects..</p>
  
  <pre><code> var array1=  
  
      [
          {
              "id": 84,
              "outputTypeId": 900000000000002,
              "previousOutputTypeActivitySeqMappingId": null,
              "isRemoved": false,
              "isPrimary": false
          },
          {
              "id": 95,
              "outputTypeId": 900000000000002,
              "previousOutputTypeActivitySeqMappingId": 84,
              "isRemoved": false,
              "isPrimary": false
          },
          {
              "id": 150,
              "outputTypeId": 900000000000002,
              "previousOutputTypeActivitySeqMappingId": 95,
              "isRemoved": false,
              "isPrimary": false
          },
          {
              "id": 160,
              "outputTypeId": 900000000000002,
              "previousOutputTypeActivitySeqMappingId": 95,
              "isRemoved": false,
              "isPrimary": false
          }
      ]
  </code></pre>
  
  <p>I wanted to convert to the below format by identifying the "id" and "previousOutputTypeActivitySeqMappingId" and pushing it into a new array called 
      <strong>items</strong></p>
  
  <pre><code>var array1=
  
      [{
          "id": 84,
          "outputTypeId": 900000000000002,
          "previousOutputTypeActivitySeqMappingId": null,
          "isRemoved": false,
          "isPrimary": false,
          "items": [
              {
                  "id": 95,
                  "outputTypeId": 900000000000002,
                  "previousOutputTypeActivitySeqMappingId": 84,
                  "isRemoved": false,
                  "isPrimary": false,
                  "items": [
                      {
                          "id": 150,
                          "outputTypeId": 900000000000002,
                          "previousOutputTypeActivitySeqMappingId": 95,
                          "isRemoved": false,
                          "isPrimary": false,
                          "items": []
                      },
                      {
                          "id": 160,
                          "outputTypeId": 900000000000002,
                          "previousOutputTypeActivitySeqMappingId": 95,
                          "isRemoved": false,
                          "isPrimary": false,
                          "items": []
                      }
                  ]
              }
          ]
      }]
  </code></pre>
  
  <p>The code that I tried is given below...
  I created a dummy object first in the new format:</p>
  
  <pre><code>var dummyObj= {
          "id": 84,
          "outputTypeId": 900000000000002,
          "previousOutputTypeActivitySeqMappingId": null,
          "isRemoved": false,
          "isPrimary": false
      }
  function populateObj(array1, arrObj) {
     for (var i = 0; i &lt; array1.length; i++) {
          if (array1[i].id == arrObj.parentActivityId) {
              array1[i].items.push(arrObj);
          } else {
              populateObj(array1[i].items, arrObj);
          }
      }
  };
  
  populateObj(dummyObj);
  </code></pre>
  
  <p>Since I don't want to hardcode a dummy object in the beginning.
  Is there any way to achieve this conversion using javascript?<br>
  Thanks.</p>