title: Google Sheet Script Editor - Ways to delete multiple tabs if the tab name isn`t found in in array
body: <p>I'm trying to delete all tabs if the actual tab naming doesn't exist in an array. </p>
  
  <p><a href="https://docs.google.com/spreadsheets/d/1IrnC-0Pa5hHez1Mg9ultO-Mp-DiR8j2KpKa3WFyrhkQ/edit?usp=sharing" rel="nofollow noreferrer">Sample data - May</a><br>
  <a href="https://docs.google.com/spreadsheets/d/1gvzD7bzDC1midVnfy6hNLSMDF6xIjqXnWsPOuej1cWk/edit?usp=sharing" rel="nofollow noreferrer">Sample Data - April</a></p>
  
  <p>I provide two samples to illustrate how raw data gets pulled in every month. In my code, I have API pulling process that does this job automatically every month. My below code here takes this raw data and splits them into separate tabs according to the "Vendor" column:</p>
  
  <pre><code>function SpreadProduct() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = SpreadsheetApp.getActiveSheet();
    var values = sheet.getDataRange().getValues();
    // remove header row values from array
    values.shift();
  
    // data structure
    var ds = {};
    values.forEach(function(row) {
      var ven = row.shift(); // 1st col
      var product = row.shift(); // 2nd col
  
      ds[ven] = ds[ven] || {};
      ds[ven][product] = ds[ven][product] || [];
      // set value on ds
  
      ds[ven][product] = [parseInt(row[0]), parseInt(row[1])];
    });
    Logger.log(ds);
    // result object, for each vendor create array of rows
    // { A: [ row, row... ]... }
    var rs = {};
    Object.keys(ds).forEach(function(v) {
      rs[v] = rs[v] || [];
      Object.keys(ds[v]).forEach(function(p) {
        if (ds[v][p]) {
          rs[v].push([p, ds[v][p][0], ds[v][p][1]]);
        } else {
          rs[v].push([p, 0, 0]);
        }
      });
    });
    Logger.log(rs);
    // write rows
    Object.keys(rs).forEach(function(v) {
      var headers = [[v, 'Product'].join(' '), 'Sales', 'leftover'];
      // insert headers into rows for writing
      rs[v].unshift(headers);
      try {
        ss.insertSheet(headers[0]);
      } catch (e) {}
      var sh = ss.getSheetByName(headers[0]);
      sh.clear();
      sh.getRange(1, 1, rs[v].length, 3).setValues(rs[v]);
    });
  }
  </code></pre>
  
  <p>The Google Sheets tables are the results of the above code.</p>
  
  <p>Now I<code>m trying to delete the tab if the following month doesn</code>t have previous month`s vendor. </p>
  
  <p>So for instance, "Month of April" doesn`t have "Apple" in the vendor column whereas "Month of March" has "Apple". </p>
  
  <p>So when I compute the table for April, the "Apple" tab was deleted </p>
  
  <p>Would there be a way to do this process programmatically in Google sheet script?</p>