8

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.

1

2 Answers 2

6

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';
}
Sign up to request clarification or add additional context in comments.

Comments

0

Used this thread to create this function for this purpose.

function includesReplacement(theArrayOrHaystack, theItemOrNeedle) {
 return (theArrayOrHaystack.indexOf(theItemOrNeedle) > -1);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.