Using JavaScript in Zapier to generate multiple values for Airtable database entries

I am attempting to create a JavaScript function within Zapier that can take two date inputs and return a list of all dates that fall between those two dates. This output should be structured in such a way that multiple records can be created in an Airtable database. According to Zapier’s documentation, when an array of objects is returned, each item in the array should invoke the subsequent steps separately.

Although I have a working code snippet, it only produces a single record containing all dates, which isn’t useful for creating date-specific entries. Here’s the code I wrote:

var startDate = new Date(inputData.start);
var endDate = new Date(inputData.end);
var datesArray = [];
while (startDate <= endDate) {
    datesArray.push(new String(startDate.toISOString()));
    startDate.setDate(startDate.getDate() + 1);
}
return {datesArray};

While the resultant datesArray is visible in the next step, it appears as a single value instead of multiple entries.

Any suggestions on how to achieve the desired format?

Emma, I think you should wrap each date in an object and return an array like: return datesArray.map(date => ({ "date": date }));. This should let Zapier break them into separate items for Airtable. Make sure your Zapier step is configured to handle arrays properly too!