I'm trying to to run a script that will wait for 1 second between loop calls. but the code won't recognize the i parameter.
for (var i = 0; i < lines.length; i++) {
var scanProgressInterval = setInterval(function(i) {
// Process the line, noting it might be incomplete.
if (lines[i].indexOf("(y/n)") > -1) {
console.log("includes (y/n)");
ws.emit('scan', JSON.stringify({scan: false, question: lines[i]}));
}
else if (lines[i].indexOf("any key") > -1) {
console.log("any key");
ws.emit('scan', JSON.stringify({scan: false, key: lines[i]}));
}
}, 1000);
}
what's wrong with this code?