Friday, May 17, 2024
164
rated 0 times [  165] [ 1]  / answers: 1 / hits: 41721  / 7 Years ago, tue, february 28, 2017, 12:00:00

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!


More From » google-sheets

 Answers
124

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.


[#58733] Monday, February 27, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
nicole

Total Points: 648
Total Questions: 95
Total Answers: 103

Location: Turks and Caicos Islands
Member since Sun, Mar 7, 2021
3 Years ago
;