title: Confirm that a value is in a spreadsheet column using Google Apps Script
body: <p>This function sends email reminders based on a few conditions. One of the things I need to check for is that the Visit ID (which is in column 11 in the "email log" sheet) exists in a separate sheet ("DATA", stored in the enrollmentData variable). How do I search this array and return the ID to match in the IF statement below?</p>
  
  <pre><code>function sendReminders() {
        var ss = SpreadsheetApp.getActiveSpreadsheet ();
        var sheet = ss.getSheetByName("Email Log");
      var rows = sheet.getLastRow()-1;
        var startRow = 2;  // First row of data to process
        var numRows = rows;   // Number of rows to process
        var now = new Date();
  
    // Fetch the range of cells
    var dataRange = sheet.getRange(startRow, 1, numRows, 22)
  
    // Fetch values for each row in the Range.
    var data = dataRange.getValues();
  
    var today = Utilities.formatDate(new Date(), "GMT-5", "m/d/yyyy")
    var reminderSent = "Reminder Sent";
  
    //get email body and subject
    var bodyTem = ss.getSheetByName("Email Templates").getRange('b8').getValues();
    var subject = ss.getSheetByName("Email Templates").getRange('d13').getValues();
  
    //get enrollments data to search for visit ID
    var enrollmentData = ss.getSheetByName("DATA").getRange('H:H').getValues();
  
    for (var i = 0; i &lt; data.length; i++) {
      var row = data[i];
  
  
  
  
     //set conditions
      var sendReminder = row[18];
      var reminderDate = row[19];
      var reminderStatus = row[20];
      var visitID = row[11]
      //need condition to look for visit ID to not include already cancelled. Search enrollmentData for visitID and return as foundID for conditional below
  
  
      if (sendReminder == "Yes" &amp;&amp; reminderStatus != reminderSent &amp;&amp; reminderDate &gt;= today &amp;&amp; visitID == foundID) {
  
  
        //assemble email
        var studentEmail = row[13];
        var firstName = row[12];
        var instructor = row[0];
        var body1 = bodyTem.replace(/*name*/gi,firstName); 
        var body2 = body1.replace(/*instructorFull*/gi,instructor);
  
  
  
        MailApp.sendEmail(studentEmail, subject, body2);
  
        //need to write in that the reminder email was sent.
        sheet.getRange(startRow + i, 20).setValue(reminderSent);
        sheet.getRange(startRow + i, 21).setValue(now);
  
  
  
  
      };
    };
  };
  </code></pre>