Firstly, I am not an expert in JS. Still learning and I have the following code and all I needed to do is console the laeve.name, leave.count... as mentioned in the latter part of the code. But it becomes undefined
all the time.
Data.forEach(async (element) => {
let newleaveData = {};
newleaveData.leave_id = element.leave_id;
let leave = this.state.allLeaves.filter((e) => e.id === element.leave_id);
let requestedArr = MainArray.filter((el) => el.leave_id === element.leave_id);
if (leave.leave_counter === "Years" || leave.leave_counter === "Months") {
newleaveData.leaveCounter = "Months";
} else {
newleaveData.leaveCounter = "Days";
}
if (requestedArr.length > 0) {
newleaveData.leaveName = leave.name;
console.log("leave obj:" + JSON.stringify(leave, null, 2));
console.log("leave name:" + leave.name);
console.log("leave count:" + leave.no_of_leaves);
console.log("leave counter:" + leave.leave_counter);
I have tried to await
the filter function since the whole function is an async
one. But it's not working. I would be very much thankful if someone can mention the mistake in this code.