0

I want to know how to add for loop for this type of code. please forget about that title, start, backgroundColor and borderColor values. I can load them using for loop. I want to know how to add one loop to print this all.

events: [
        {
          title: 'All Day Event',
          start: new Date(y, m, 1),
          backgroundColor: "#f56954", //red
          borderColor: "#f56954" //red
        },
        {
          title: 'Long Event',
          start: new Date(y, m, d - 5),
          end: new Date(y, m, d - 2),
          backgroundColor: "#f39c12", //yellow
          borderColor: "#f39c12" //yellow
        },
        {
          title: 'Meeting',
          start: new Date(y, m, d, 10, 30),
          allDay: false,
          backgroundColor: "#0073b7", //Blue
          borderColor: "#0073b7" //Blue
        },
        {
          title: 'Lunch',
          start: new Date(y, m, d, 12, 0),
          end: new Date(y, m, d, 14, 0),
          allDay: false,
          backgroundColor: "#00c0ef", //Info (aqua)
          borderColor: "#00c0ef"//Info (aqua)
        },
        {
          title: 'Birthday Party',
          start: new Date(y, m, d + 1, 19, 0),
          end: new Date(y, m, d + 1, 22, 30),
          allDay: false,
          backgroundColor: "#00a65a", //Success (green)
          borderColor: "#00a65a" //Success (green)
        },
        {
          title: 'Click for Google',
          start: new Date(y, m, 28),
          end: new Date(y, m, 29),
          url: 'http://google.com/',
          backgroundColor: "#3c8dbc", //Primary (light-blue)
          borderColor: "#3c8dbc" //Primary (light-blue)
        },
      ],
Ramkee
  • 900
  • 1
  • 10
  • 27
  • 2
    Possible duplicate of [Loop through array in JavaScript](http://stackoverflow.com/questions/3010840/loop-through-array-in-javascript) – Maks3w Mar 09 '16 at 05:26

1 Answers1

2

If you have separate arrays for all elements (title[] , start[], end[] etc..) then you may try this below

 var main_array = [];

for (var i = 0; i < title.length; i++) {

        main_array.push({
            "title" : title[i],
            "start" : start[i],
            "end" : end[i],
            "allDay" : allDay[i],
            "backgroundColor" : backgroundColor[i],
            "borderColor" : borderColor[i]
        });

}