TypeError: calendar.getName is not a function

Viewed 47

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());
}
1 Answers

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);
}
Related