'Loop through Object of Sheets JavaScript

I'm using import * as XLSX from 'xlsx' and I'm trying to loop through an Object containing excel sheets. Everything was fine and dandy when I had one spreadsheet since I could easily access the length. My specifications changed and I need to be able to send to a DB only specific worksheets the user selects from the excel file. I don't know much about JavaScript but for some reason, I had to parse the data after stringifying it to be able to recognize the headers from the excel file. This is some of the code I have:

      if (this.selectedDepartment.includes("CSET")) {
        var sheet_name = workbook.SheetNames[4];
        var worksheet = workbook.Sheets[sheet_name];
        var classData = XLSX.utils.sheet_to_json(worksheet, { raw: true });
        XLSX.utils.book_append_sheet(newWorkbook, classData, "CSET");
      }
      if (this.selectedDepartment.includes("COMM")) {
        sheet_name = workbook.SheetNames[5];
        var worksheet = workbook.Sheets[sheet_name];
        classData = XLSX.utils.sheet_to_json(worksheet, { raw: true });
        XLSX.utils.book_append_sheet(newWorkbook, classData, "COMM");
      }
      var classData_JSON = JSON.stringify(newWorkbook);
      var json = JSON.parse(classData_JSON);

Below, trying to store into my array:

 for (var i = 0; i < json.length; i++)
      {
        var _courseID = json[i].Subject + " " + this.courseID[i];
        this._newClasses[i] = {
          'CRN': json[i].CRN, 'Subject': json[i].Subject, 'CourseID': _courseID, 'Section': json[i].Section, 'UserID': json[i].UserID, 'Max': json[i].Max,
          'CourseComments': json[i]["Course Comments"], 'Monday': this.Monday[i], 'Tuesday': this.Tuesday[i], 'Wednesday': this.Wednesday[i], 'Thursday': this.Thursday[i]
          // more code
        this.classService.Put_Classs(this._newClasses[i]).then(classData => classData.subscribe());

My problem if you look in the picture is I can't find a way to loop through one sheet at a time, get the sheet name during runtime, and then loop through that sheet and store into my array before moving on to the next one. COMM and CSET both have the length property but I'm not sure how to access this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source