admin管理员组

文章数量:1399997

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.

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.

Share Improve this question asked Jan 15, 2015 at 15:44 user3685412user3685412 4,5773 gold badges17 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

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.

本文标签: