Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Spreadsheet: TypeError Cannot find function indexOf in object 0 (Line 7 in Code.gs)

so I am trying to make my code work. It does... sometimes.

The code is:

function getAntallVakter(tabell, navn) {

  var antall = 0;

  for(i = 0; i<tabell.length;i++){
    for(j=0;j<tabell[i].length;j++){
      if(tabell[i][j].indexOf(navn)>-1){
        antall += 1;
      }
    }
  }
  return antall;
}

It does work when I tested it, but when I used it on the spreadsheet that needs this script it doesn't work for the given range. It does work on other ranges. On the specific ranges it doesn't work I got some of these error:

TypeError Cannot find function indexOf in object 0 (Line 7 in Code.gs)
TypeError Cannot find function indexOf in Thu Jan 01 2015 00:00:00 GMT+0100 (CET).

I appreciate any help I get.

like image 354
user3685412 Avatar asked Mar 17 '23 08:03

user3685412


1 Answers

I can't belive I totally forgot to check weather the cells are strings or not.

adding the line

var text = tabell[i][j].toString();

before the if-sentence fixed everything.

like image 72
user3685412 Avatar answered Apr 28 '23 04:04

user3685412