Issue
The problem arises when viewing the exported excel file where undefined
is displayed. However, upon investigation, there are no empty array indexes causing this confusion.
Solution Attempt
const joinDate = new Date(obj.date);
let snap = [
obj.name,
obj.surname,
obj.email,
obj.nip,
obj.phone,
obj.address + " " + obj.home + " " + (obj.local=="brak" ? "" : obj.local),
obj.city,
obj.zip,
obj.spentPoint,
'',
''
];
orders.push(new Promise((resolve) => {
let userNip = i;
let ordersRef = firebase.database().ref('/orders/' + userNip);
ordersRef.once("value", (snapshot) => {
let ord = snapshot.val();
let i = 0;
for(let u in ord) {
let o = ord[u];
let newDate = new Date(o.date);
let formattedDate = String(newDate.getDate()) + "/" + String(newDate.getMonth()+1) + "/" + String(newDate.getFullYear());
snap[10+i] = formattedDate;
for(let x in o.items) {
snap[9+i] += String(o.items[x].title) + "[ Points: " + o.items[x].summary + " ]";
}
i = i + 2;
}
resolve();
})
}));
data.push(snap);
In the excel sheet, the output appears as:
Name Surname ..... 1st product name, 1st product date, undefined2nd product name, 2nd product date.
The source of the undefined value remains elusive.
Upon thorough inspection, it is confirmed that the data array contains no missing values that could result in the appearance of 'undefined'.
https://i.sstatic.net/fSFDz.png
A red line has been marked indicating the problematic area, persisting with the 3rd, 4th, and subsequent items...
Is there a solution to this issue?