How do you create a for-each loop in Google Apps Script?
I'm writing an email script with GAS, and I'd like to iterate through an array using a for-each loop, rather than a regular for-loop.
I've already seen this answer, but the object is undefined, presumably because the for loop doesn't work.
// threads is a GmailThread[]
for (var thread in threads) {
var msgs = thread.getMessages();
//msgs is a GmailMessage[]
for (var msg in msgs) {
msg.somemethod(); //somemethod is undefined, because msg is undefined.
}
}
(I'm still new to javascript, but I know of a for-each loop from java.)
thread.map(handleThread)
or something along those lines – Robin Gertenbach