Search code examples
cordovaionic-frameworkionic2cordova-plugins

How to push Ionic CalendarPlugin data to array


Calendar.findAllEventsInNamedCalendar("Calendar").then(data =>

Hello, I am using Eddy Verbruggen's plugin to pull events from an IOS calendar. I want to store these into an array. How would I do so? So far the events from Calendar are coming out but not sure how to store x amount in an array.


Solution

  • As per the site, the response is something like,

    {
    calendar: "Kalender",
    endDate: "2016-06-10 23:59:59",
    id: "0F9990EB-05A7-40DB-B082-424A85B59F90",
    lastModifiedDate: "2016-06-13 09:14:02",
    location: "",
    message: "my description",
    startDate: "2016-06-10 00:00:00",
    title: "myEvent"
    }
    

    So, this is a common example of a JSON array object.

    To access it, you can iterate through the "data" object array.

    Calendar.findAllEventsInNamedCalendar("Calendar").then(data =>
    ....
     for(var key in data){
      console.log(data[key]);
     }
    

    To access a specific value in that object would be

    for(var key in data){
     console.log(data[key].id);
    }
    

    To store it,

     var test ;
     test = data;
    

    this would then store the data into the test, in which u can iterate through the same as per above.