How to return array of items

Hi, I’m very new to n8n. My coding skills are very basic though.
I have function that calculates difference between parsed dates. For example I get this JSON data from previous nodes(3 items):

[
{
"UID": 2,
"USER_ID": 8593847591,
"USERNAME": "John",
"PUBLISH_DATE": 1641789802000,
"CURRENT_DATE": 1642058123000
},
{
"UID": 8,
"USER_ID": 59384595045,
"USERNAME": "Susan",
"PUBLISH_DATE": 1641952418000,
"CURRENT_DATE": 1642058123000
},
{
"UID": 9,
"USER_ID": 9504832934,
"USERNAME": "Chris",
"PUBLISH_DATE": 1641836651000,
"CURRENT_DATE": 1642058123000
}
]

and after function I get only 1 item instead of 3 calculations. I understand that I need to use array, but I don’t know how to do it correctly and I get an error:
“Always an Array of items has to be returned!”

Hi @vlrpsknv, welcome to the community!

I am not sure I fully understand your question. When running your example Function code I don’t get the Always an Array of items has to be returned! error you have described and your data structure seems to be correct:

Do you want to perform this calculation (CURRENT_DATE minus PUBLISH_DATE) for each input item? If so, you might want to use the Function Item node instead of the Function node as this would run once for each input item. Here is an example workflow demonstrating the idea:

Example Workflow

1 Like