title: JavaScript How to convert a string into a nested object
body: <p>I have a response string like this:</p>
  <pre><code>|||COVID HPI^^^FEVER^^^Low Grade
  |||COVID HPI^^^FEVER^^^Continuous
  |||COVID HPI^^^RHINORRHEA/SNEEZING^^^No
  |||GENERAL EXAM^^^CL^^^Conscious
  |||GENERAL EXAM^^^ORIENTED^^^Yes
  </code></pre>
  <p>And i want to convert it into something like this:</p>
  <pre><code>{
    &quot;COVID HPI&quot;: [
      {
        &quot;FEVER&quot;: &quot;Low Grade, Continuous&quot;,
        &quot;RHINORRHEA/SNEEZING&quot;: &quot;Yes&quot;
      }
    ],
    &quot;GENERAL EXAM&quot;: [
      {
        &quot;CL&quot;: &quot;Conscious&quot;,
        &quot;ORIENTED&quot;: &quot;Yes&quot;
      }
    ]
  }
  </code></pre>
  <p>I am not able to go beyond this without an ugly code:</p>
  <pre><code>const na = [];
      fetch('http://localhost/test/json/newdata.json')
      .then(response =&gt; {
         let vv = response.json();
         return vv;
      })
      .then(function(data){
      console.log(data[0]['tRxVal'])
          let nav = data[0]['tRxVal'].slice(3).split('|||');
          let nbv = nav.map(function(item,i){
              return item.split('^^^');
          });
          //console.log(nbv);
          nbv.forEach(function(v,i){
              if(!na.includes(v[0])){
                  na.push(v[0]);
              }
          })
          console.log(na)
  
      })
      .catch(err =&gt; {
          // handle errors
      });
  </code></pre>
  <p>Can someone please help me with this
  Thanks</p>