Rafa Rafa - 1 month ago 18
Javascript Question

Push Values Calendar API

I'm having issues in pushing and returning an array with the events titles. As far as i'm concerned, this should append the title of the events into the titulos array.

for (j=0;j<events.length;j++){
var titulos = []
var events =a.getEventsForDay(testingstartdate, {search: 'OOO'});
var eventstitle = events[j].getTitle();
Logger.log(eventstitle);
titulos.push(eventstitle);
};


The Logger.log in question here is returning correctly one row per title, so no sure why the final array is only pushing 1 single value to it.

Any ideas?

Answer

The Logger.log in question here is returning correctly one row per title, so no sure why the final array is only pushing 1 single value to it.

This is happening because you define your array in each step of the for loop. Moving the following statement:

var titulos = [];

before the start of the for loop will solve your problem.

Comments