How to add events in javascript fullCalendar

I am trying this library for the first time
want to set events to my calendar, but instead of doing this:

var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
    initialView: 'dayGridMonth',

    titleFormat:{
        year: 'numeric',
        month: 'short'  
    },

    events: [{
        title: "February Outing",
        start: "2021-02-19",
        end: "2021-02-21"
    }]
});

calendar.render();

I Want to do it like this for some reason

    var calendarEl = document.getElementById('calendar');
    var calendar = new FullCalendar.Calendar(calendarEl, {
        initialView: 'dayGridMonth',

        titleFormat:{
            year: 'numeric',
            month: 'short'  
        },
   });


let myEvents = [
    {
        title: "February Outing",
        start: "2021-02-19",
        end: "2021-02-21"
    }
]

calendar.events = myEvents
calendar.render();

but it doesn’t work
Thank you in advance:)

1 thought on “How to add events in javascript fullCalendar”

Leave a Comment