title: Grouping array into one
body: <p>There is one array that contains <code>appointmentID</code> (first value) and <code>supperBillID</code> (second value) separated by a comma. The <code>AppointmentID</code> will be unique but <code>superBillID</code> can be the same in consecutive position only. What I want is one array that contains all the <code>appointmentID</code> values, which have same <code>billingID</code>, separated by comma.</p>
  
  <p>I wrote the below code but I'm not getting the proper output:</p>
  
  <pre><code>var fg = ['10000021,23', '10000022,23', '10000023,24', '10000024,25', '10000025,25', '10000026,25', '10000027,26', '10000028,27'];
  var tab = [];
  var gbl = 0;
  
  for (var i = 0; i &lt; fg.length; i++, gbl++) {
      var vb = fg[gbl].split(',')[1]; // Will use try catch here
      var mainAr = fg[gbl].split(',')[0];
  
      for (var j = i + 1; j &lt; fg.length; j++) {
          if (vb == fg[j].split(',')[1]) {
              mainAr = mainAr + ',' + fg[j].split(',')[0];
              gbl++;
          }
          else {
              break;
          }
          tab.push(mainAr, vb);
      }
  }
  </code></pre>
  
  <p>Sample Input:</p>
  
  <pre><code>var input = ['10000021,23', '10000022,23', '10000023,24', '10000024,25', '10000025,25', '10000026,25', '10000027,26', '10000028,27'];
  </code></pre>
  
  <p>Expected Output:</p>
  
  <pre><code>output = ['10000021,10000023',23]
           ['10000023',24]
           ['10000024,10000025,10000026',25]
           ['10000027',26]
           ['10000028',27]
  </code></pre>