简体   繁体   中英

Google spreadsheet script: toString() not returning a string?

I'm writing a very simple google spreadsheets script and need to compare strings. For some reason, when I call toString() on the content of a cell, I get a type error: "TypeError: Cannot find function includes in object Semester Long Clinics. (line 6)", where in this case "Semester Long Clinics" is the actual content of the cell. Here's the code:

function getStudents(input, clinicName, columnNumber) { 
  var toPrint = []
  var i = 0; 
  for(i; i < 43; i++){
  var toCheck = input[i][columnNumber - 1].toString()
   if(toCheck.includes(clinicName)){
      toPrint.push(input[i][0].toString() + ", " + input[i][1].toString() +     ", " + input[i][2].toString())
     }
  }
  return toPrint
}

The only explanation I can think of is that the input array contains instances of some sort of object that resists the standard toString() method, but I'm not sure what the advantages of that would be. Any help is much appreciated!

I don't think the error is due to the toString Function rather with this function

toCheck.includes(clinicName)

Since your error is on line 6 and it says cannot find the function includes in the object/string "Semester Long Clinics", which is the content of that array/cell.

You can try this instead

if( toCheck.indexOf(clinicName) != -1)

Just might be that the function "includes" is not supported by Apps script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM