In my Google Apps Script, I created a function to retrieve the date and subject of emails with a specific label in Gmail. However, when attempting to store each result as an object, I encountered a
SyntaxError: unexpected token ':'
issue. Although using a list to store data pairs solves the problem, I prefer key-value pairs for easier access by label.
Below is a simplified version of the function demonstrating what works and what doesn't:
function displayEmailParts() {
var labelName = 'foo';
var threads = GmailApp.getUserLabelByName(labelName).getThreads();
var initialMessages = threads.map((x) => x.getMessages()[0]);
// this works:
var messageParts = initialMessages.map(
(x) => [x.getSubject(), x.getDate()]
);
// this gives a syntax error:
var messageParts = initialMessages.map(
(x) => {subject: x.getSubject(), date: x.getDate()}
);
return messageParts
}
Why is it not valid to have an object as the output of a map call over an array?