title: How to use the function .getLastRow() in google script
body: <p>I'm pretty new to Google Script and I've been working on a line of code that is bothering me right now. What I'm trying to do is make the computer read through a range of cells in the spread sheet, then print them all out, but stop at the last row. But, as I've tried using the function .getLastRow() in the for loop or just making a variable, it doesn't work.  (There are some parts where the code is redundant and not related to the problem so you can ignore that.)</p>
  
  <pre><code>function myFunction()
  {
  
    var spreadSheet = SpreadsheetApp.openById("1F4zEJXKN3iobK8b89Ub94dd77Tdk70H0X8aFCSCmvRs");
    var activeSheetOne = spreadSheet.getSheetByName("New Family Responses");
    var activeSheetTwo = spreadSheet.getSheetByName("Existing Family Responses");
  
    var readingGender = activeSheetOne.getRange("E3:E").getValues();
    var lastRow = readingGender.getLastRow();
    var loopVar = 0;
  
    for (var i=0; i &lt; lastRow; i++) {
      Logger.log(readingGender[loopVar][0]);
      loopVar = loopVar + 1;
    }
  
  }
  </code></pre>