Possible Duplicate:
Safest Way to Loop Over Javascript Object
I have this hard coded snippet of code in JavaScript and I would like to know if it is possible to make it dynamic with a for loop. My problem is that I don't know exactly how to output the values in the JavaScript file.
function getEventData() {
return {
events: [
{
"id":1,
"start": new Date(year, month, day, 12),
"end": new Date(year, month, day, 13, 30),
"title":"Check Up"
},
{
"id":2,
"start": new Date(year, month, day, 14),
"end": new Date(year, month, day, 14, 45),
"title":"Free Trial",
readOnly: true
},
{
"id":3,
"start": new Date(year, month, day + 1, 17),
"end": new Date(year, month, day + 1, 17, 45),
"title": "Consultant"
},
{
"id":4,
"start": new Date(year, month, day - 1, 8),
"end": new Date(year, month, day - 1, 9, 30),
"title":"Check Up"
}
]
};
}
Thats the hard coded JavaScript code. Is it possible to loop through a list and output the values kinda like this:
for(var i = 0; i < listEvents.lenght; i++)
{
{
"id": listEvents[i].Id,
"start": listEvents[i].Start,
"end": listEvents[i].End,
"title": listEvents[i].Title
},
}
Thanks a lot for your help.. much appreciated.