I'm having an issue with my code. Been trying for some time to get a value from an object or arrays. I'm using a loop to get through each value in the array from the object. I get the value when I hard code the position on the value but undefined when I use the value 'num' from the loop?
for(var num = 0; num <= 6; num++){
// sets the date from the start of the week.
newDate = moment().startOf('week').weekday(num).toDate();
if(timesheet.timesheet.start[num] === ''){
....
} else {
Times.create(timesheet, function(err, newTimes) {
if(err){
console.log(err);
} else {
newTimes.timesheet.id = newTimesheet.id;
// Prints the value fine
console.log(timesheet.timesheet.start[0]);
// Gives me undefined?
newTimes.start = timesheet.timesheet.start[num];
newTimes.end = "On";
newTimes.save();
newTimesheet.times.push(newTimes);
newTimesheet.save();
}
});
}
}