I'm working with a JSON that contains multiple objects, and it's possible for this JSON string to have more data/objects than just three. My goal is to create an array of objects regardless of how much information is included.
[ {"endDate":"2017-04-18","nrC":2,"type":"CO","dataD":"2017-04-19","startDate":"2017-04-16"},
{"endDate":"2017-04-27","nrC":4,"type":"CP","dataD":"2017-04-23","startDate":"2017-03-26"},
{"endDate":"2017-04-27","nrC":7,"type":"CA","dataD":"2017-04-23","startDate":"2017-04-26"}
]
var USER_DAYS = {};
for(var i=0;i<json.length;i++){
var USER_DAYS = [
{
id: json[i].nrC,
date: json[i].dataD,
title: json[i].type,
start: new Date(json[i].startDate),
end: new Date(json[i].endDate),
allDay: true
},
];
console.log(i); // displays 1, 2, 3
}
console.log(USER_DAYS) // shows only the last object from the json.
The JavaScript variable USER_DAYS
should be an array containing n objects when printed, but currently only one object is being displayed in my console instead of the desired three.
I am looking to populate the USER_DAYS
variable with all objects from the JSON provided.