I'm trying to call an external variable in a forEach context. Since I'm using an arrow notation this should make the trick but the variable still comes out as undefined.
This is my code:
transformSlots (slots) {
var array = slots;
var newArray;
array.forEach(element => {
var newElement = {
day: dateFns.getDate(element.slot),
month: dateFns.getMonth(element.slot),
year: dateFns.getYear(element.slot),
hour: dateFns.getHours(element.slot),
numInterview: element.num,
id_users_pending: 0,
id_users_accepted: 0
};
this.newArray.push(newElement);
});
return array;
}
EDIT: If I take .this away the result is exactly the same.
this.newArray.push(newElement);tonewArray.push(newElement);not assigned any value like empty array. so. doing newArray.push(newElement); will also be wrong. instarting it should bevar newArray = []then,newArray.push(newElement);