title: google scripts: hide sheet by exact name
body: <p>I have a google sheets file that contains 1 tab per day and the name of each tab is adate in d MMMM yyyy format. Now I have created a script that runs through the file and hides any tabs of which the name is older than today-14, which works beautifully BUT: for some reason it does not look for an exact match but a <em>contains</em> match. so for example if it looks for 1 december, it will hide also 11 december as that contains 1 december as well.</p>
  <p>Question; How would you suggest I adjust the script to search and hide only an <em>exact</em> match?</p>
  <pre><code>// Get list of sheet names in an array format
  function sheetnames() {
  // Define array
  var out = new Array()
  // Get sheets
    var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
  // get current month
    var testDate = new Date();
    var date = new Date();
    date.setDate(testDate.getDate()-14);
    var secondDate = Utilities.formatDate(date, Session.getScriptTimeZone(), &quot;d MMMM&quot;).toLowerCase();
    Logger.log(secondDate);
  // Work through each sheet one at a time
    for (var i=0 ; i&lt;sheets.length ; i++) {
  // define the current sheet
      var curSheetName = sheets[i].getName();
  // determine if matches criteria
  if (curSheetName.indexOf(secondDate) !== -1) {
   sheets[i].hideSheet();
  }
      }
    }
  </code></pre>