The code is as follows
var mailArchive = {0: "Dear nephew, ... (mail number 1)",
1: "(mail number 2)",
2: "(mail number 3)"};
for (var current = 0; current in mailArchive; current++)
print("Processing e-mail #", current, ": ", mailArchive[current]);
I would think current < mailArchive.length would be a better closure condition….
Does current in mailArchive accomplish the same thing, as it appears to in the interpreter (required for print function)? If not, what does it accomplish and how?
Yes, it works in the interpreter, I tested it with a
node.jsinteractive session.mailArchive.length, however, will not work asmailArchiveis an Object, not an Array, so doesn’t have a property namedlength.current in mailArchivechecks whether the objectmailArchivehas a property with the name given in the variablecurrent.As you may or may not know, however, this approach is not usual for JavaScript. Much more common is to make
mailArchivean array instead and use the usual conditioncurrent < mailArchive.length