So, I have an array of three objects. They have a name and a type property (and various others). I want to loop through each of them and use the readline
module to get user input for all of them. Here's the javascript code I use to do this (using the async
module):
async.each(questions.q, function (e, cb) {
if (e.type === "s") {
//not important
} else if (e.type === "q") {
rl.question(e.name, function (a) {
//do stuff
cb();
});
}
}, function (err) {
if (err) throw err;
});
(question.q
is the array of elements)
However, the output for all three of my objects with the type
q
is the following:
Question1Question2Question3 //input
Instead of doing one at a time, each
prints all 3 out and then awaits an input. Why is this and how can I fix it?