0

I don't want to use a setTimeinterval function every-time as mentioned here Loop every five seconds in Javascript as it is not iterating over an array but looping it for every five seconds. But I want something that needs to execute after every five seconds till iteration of array elements is done.

const csv = require('csv-parser');
const fs = require('fs');
const results = [];
fs.createReadStream('csvlist1.csv')
    .pipe(csv())
    .on('data', (data) => results.push(data))
    .on('end', () => {
        results.forEach((e) => setTimeout(() => log(e), 1000));
    });

function log(e) {
    console.log(e);
}

consider the above code. When it is executed it should print the elements in the results array one by one after every 1 second. Thank's in advance.

Rohit Sharma
  • 3,304
  • 2
  • 19
  • 34
classydraught
  • 352
  • 1
  • 4
  • 13

0 Answers0