Answer the question
In order to leave comments, you need to log in
Why is a local variable just taken and set to zero?
Either I don't understand something, or JavaScript should be banned by law and equated with extremism...
async uploadCSV(file: Express.Multer.File) {
const errorsOnLines: number[] = [];
const csvString = Buffer.from(file.buffer).toString('utf-8');
const pupils = await csvtojson({
ignoreEmpty: true,
maxRowLength: 9,
delimiter: 'auto'
}).fromString(csvString);
pupils.forEach(async (pupil: createPupilDTO, index: number) => {
pupil.age = moment(pupil.age, 'DD.MM.YYYY').toISOString();
try {
await this.PupilModel.validate(pupil);
} catch (err) {
errorsOnLines.push(index + 2);
}
});
console.log(errorsOnLines)
}
errorsOnLines
filled with two, three values, and so on. But as soon as execution gets to console.log()
I get []
. Answer the question
In order to leave comments, you need to log in
Or I don't understand somethingDo not understand the meaning of the word asynchronous
console.log
works out before anyone elseerrorsOnLines.push
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question