title: Loop through Object of Sheets JavaScript
body: <p>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:</p>
  <pre><code>      if (this.selectedDepartment.includes(&quot;CSET&quot;)) {
          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, &quot;CSET&quot;);
        }
        if (this.selectedDepartment.includes(&quot;COMM&quot;)) {
          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, &quot;COMM&quot;);
        }
        var classData_JSON = JSON.stringify(newWorkbook);
        var json = JSON.parse(classData_JSON);
  </code></pre>
  <p>Below, trying to store into my array:</p>
  <pre><code> for (var i = 0; i &lt; json.length; i++)
        {
          var _courseID = json[i].Subject + &quot; &quot; + 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][&quot;Course Comments&quot;], '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 =&gt; classData.subscribe());
  </code></pre>
  <p>My problem if you look in the <a href="https://i.stack.imgur.com/JmrNZ.png" rel="nofollow noreferrer">picture</a> 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.</p>