Home > Mobile >  TypeError: calendar.getName is not a function
TypeError: calendar.getName is not a function

Time:01-17

Why do I try to use getname(), the console gives me an error?

var cList = CalendarApp.getAllCalendars();
for (calendar in cList) {
  calendarList.push(calendar.getName());
}

CodePudding user response:

Looks like there's a bit of an issue using the for...in loop.

In the snippet shared, calendar is just an index (number) and accordingly, you could make use of something like this —

function myFunction() {
  var cList = CalendarApp.getAllCalendars();
  var calendarList = [];
  for (calendar in cList) {
    calendarList.push(cList[calendar].getName());
  }
  console.log(calendarList);
}
  •  Tags:  
  • Related