I have a function that takes, as an argument, the response from the gapi.client.calendar.events.list
call on the Google Calendar API.
I'm trying to iterate through that response, and .push()
the elements to an array (localEventList
). When I check the value of localEventList
immediately after the for-loop, the events are stored in it, but when I check it outside of .execute(function(events){...
function, the array is still empty. I've tried initializing the array to different values, and the array remains at the value it is initialized to.
I don't understand why the variable isn't staying mutated, since it's initialized in the overarching function call. Also, I'm not really clear on the purpose of the .execute(...
call.
If anyone could clarify either of these two issues, I'd love you forever.
function parseEvents(calEventRequest){
var localEventList = new Array();
calEventRequest.execute(function(events){
for(i = 0; i < events.items.length; i++){
var item = events.items[i];
var name = item.summary;
var start = item.dateTime;
localEventList.push(name);
};
// If I place a console.log(localEventList) here, the array is populated
});
console.log(localEventList); // But the call here displays an empty array.
}