Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: Cannot find function includes in object (even though the object is an array)

Why does app scripts not find the function includes in the object that is clearly an Array.

function test() {
  var list = ['a', 'b', 'c'];
  Logger.log(list.constructor.name) // Array
    if ( list.includes('a') ){
      Logger.log('yes');
    } 
 return 'done';
}

The error text:

TypeError: Cannot find function includes in object a,b,c. (line 134, file "Code")

I am new with google app scripts and I am getting mad. I have tried it in a online Javascript console and everything is fine.

like image 223
cek11lru Avatar asked Jul 11 '18 18:07

cek11lru


1 Answers

Due to the comment that helped, this is an alternative solution.

function test() {
  var list = ['a', 'b', 'c'];
  Logger.log(list.constructor.name) // Array
  if ( list.indexOf('a') > -1 ){
      Logger.log('Yes'); // 'Yes'
  } 
return 'done';
}
like image 171
cek11lru Avatar answered Oct 03 '22 05:10

cek11lru