I encountered an issue in my table where I get the error message value is not iterable
when there is no value to iterate through. How can I handle this error in my code?
Snippet of Code:
if (null != data && data) {
data = data.map((item) => {
const value = item.deadlineEntityList;
delete item.deadlineEntityList;
const deadlines = [];
for (const deadlineEntity of value) { // This is where the Error occurs
deadlines.push({
deadlineId: deadlineEntity.deadlineId,
period: deadlineEntity.deadlinePeriod,
value: deadlineEntity.value
});
}
return {...item, ...{ deadlines }};
});
const rows = [];
const salesAreaNames = _.uniq(data.map((d) => d.kagName)) as string[];
for (const n of salesAreaNames) {
const salesAreaData = data.find((d) => d.kagName === n);
if (salesAreaData && salesAreaData !== null) {
const row: any = { kagName: salesAreaData.kagName, values: {}, mandantKagId: salesAreaData.mandantKagId };
for (const deadline of salesAreaData.deadlines) {
row.values[deadline.period.toLowerCase()] = this.transformAmount(deadline.value);
}
rows.push(row);
}
}
this.data = rows;
}