title: Return index of matched array not working - Javascript Google Apps Script
body: <p>I have a spreadsheet and row #1 has dates in each cell going across</p>
  <p>I want to return the column number whenever that column matches today's date. First header starts in cell B1.</p>
  <p>I am using the following and I can get it to work, but when instead I do 'return i', it always returns '0'.</p>
  <pre><code>function getColumnIndex() {
    var spreadsheet = SpreadsheetApp.getActive();
    var sheet = spreadsheet.getActiveSheet();
    var lastColumn = sheet.getLastColumn();
    var data = sheet.getRange(1,2,1,lastColumn).getValues(); //create an array of data from row 1
    for (var i = 0; i &lt;= data.length; i++) {
      var dateToday = Utilities.formatDate(new Date(), &quot;EST&quot;, &quot;MM/dd/yyyy&quot;)
      if (data[i] == dateToday) {break};
      {  
        return i;
      }
    }
  }
  </code></pre>
  <p>Now if I switch the last line 'return i' to 'return dateToday' the function will work and it will return the correct date so I know it's matching properly (and if I change row cells to other values it will return those values if it matches). I just can't get it to spit out the index number when I put 'return i'.</p>