Q:

Build array with all elements with specific class using JS

I have a table with multiple rows. I need to get the text from specific rows and build an array which I can pass on and access later. I created a jsfiddle with the code that I am using:
https://jsfiddle.net/h6x2sqk2/3/
The problem is that everything is doubled:
[
  {
    "drdsc":"DSCDS0101101",
    "bkpsets":[
      {
        "backpset":"Backup1",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup2",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup3",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup4",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      }
    ]
  },
  {
    "drdsc":"DSCDS0202202",
    "bkpsets":[
      {
        "backpset":"Backup1",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup2",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup3",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup4",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      }
    ]
  }
]

Result that I need is:
[
  {
    "drdsc":"DSCDS0101101",
    "bkpsets":[
      {
        "backpset":"Backup1",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup2",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      },
      {
        "backpset":"Backup3",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      }
    ]
  },
  {
    "drdsc":"DSCDS0202202",
    "bkpsets":[
      {
        "backpset":"Backup4",
        "srvrolenotes":"",
        "setsize1notes":"",
        "setsize2notes":""
      }
    ]
  }
]

A:

Try my suggestion here. What i did is to read from one backup till the other what you have in the tr sections
working example
    $( document ).ready(function() {
    var dscarray = $('.bkpsrvdsc').map(function() {
      var $dsclient = $(this);
      var $rows = $dsclient.closest('tr').nextUntil('tr:has(.drbkpsetdsc)');

      var drbkparray = $dsclient.closest('tr').nextUntil('tr:has(.bkpsrvdsc)').find('.drbkpset').parent().map(function() {
        var $backuppset = $(this);
        var obj = { backpset: $backuppset.text() };
var $rows = $backuppset.closest('tr').nextUntil('tr:has(.drbkpset)');
          obj['srvrolenotes'] = $rows.find('.srvrolenotes').val();
          obj['setsize1notes'] = $rows.find('.setsize1notes').val();
          obj['setsize2notes'] = $rows.find('.setsize2notes').val();

        return obj;
      }).get();

      var obj = { drdsc: $dsclient.text(), bkpsets: drbkparray };

      return obj;

    }).get();

  console.log(dscarray);
});

