title: How do I get the row number of a Google Sheets cell that contains a specific value in Google Apps Script?
body: <p>I'm trying to create a roll marking system that reads from a Google Sheets spreadsheet, takes input via a Telegam bot, and fills in checkboxes on the Google Sheet. The flow is as follows:</p>
  <ol>
  <li><p>User picks a class (e.g. Year 7-8 Girls) via Telegram bot: <a href="https://imgur.com/v9PAgXR" rel="nofollow noreferrer">https://imgur.com/v9PAgXR</a></p>
  </li>
  <li><p>Look through Google Sheet for cells containing the class name (7-8 G): <a href="https://imgur.com/yuCckA1" rel="nofollow noreferrer">https://imgur.com/yuCckA1</a></p>
  </li>
  <li><p>Extract the students' names from rows containing the class name, then presents them in a Telegram poll: <a href="https://imgur.com/q20I4iw" rel="nofollow noreferrer">https://imgur.com/q20I4iw</a></p>
  </li>
  <li><p>Check the boxes corresponding to the student names.</p>
  </li>
  </ol>
  <p>Everything is going pretty well until step 4, where I can't seem to be able to get the actual row number that the student data came from, so I can't tell the script which checkbox to manipulate.</p>
  <p>Here are some code snippets to give an idea of what I'm doing (I'm very new to all of this so open to suggestions/improvements):</p>
  <pre><code>  if (contents.message) { // If the bot receives a regular message
      var id_message = contents.message.from.id; 
      var firstName = contents.message.from.first_name;
      sendText(id_message, &quot;Hi &quot; + firstName +  &quot;! Please choose a year group.&quot;, keyBoard)
    }
  
    else if (contents.callback_query) { // If the bot gets an inline keyboard input
      var names = [];
      var id_callback = contents.callback_query.from.id;
      var data = contents.callback_query.data;
      var filteredRows = rows.filter(function(row){
      if (row[4] == data) { // If the row contains the class code
        return row
      }
      });
  
      filteredRows.forEach(function(row) {
        names.push(row[0] + &quot; &quot; + row[1]) // Compile a list of the students in the class
      });
  
      if (filteredRows.length &lt;= 10) { //
        sendPoll(id_callback,names)
      }
  
      else if (filteredRows.length &gt;= 11) { //To get around the 10 option maximum for polls
        sendPoll(id_callback,chunkArray(names,9)[0])
      }
    }
  </code></pre>
  <p>And the code for sending the poll (completely hacky solution just as a proof of concept that I can manipulate the checkboxes). Someone please show me a better way of doing the string manipulation at the start, because it shouldn't take this many steps to go from &quot;[1,2,3,4,5]&quot; to &quot;12345&quot;!</p>
  <pre><code>  else if (contents.poll_answer) { // If the bot receives a poll response
    var pollOptions = JSON.stringify(contents.poll_answer.option_ids);
    var sliced = pollOptions.replace(/,/g,&quot;&quot;);
    sliced = sliced.slice(1,-1);
    var i = sliced.length;
  
      if (pollOptions != '[]') {
        while (i--) {
          ss.getRange(&quot;H&quot;+(parseInt(sliced.charAt(i),10)+7)).setValue(&quot;TRUE&quot;)
        }
      }
  
      else if (pollOptions == '[]') {
        ss.getRange(&quot;H7:H13&quot; ).setValue(&quot;FALSE&quot;)        
      }
    }
  </code></pre>