n8n LabBeginner
Count Items in an Array in n8n
Only process emails that have attachments. Count the attachments array first.
Live Execution Simulator
Idle
π₯
Incoming Data
βοΈ
n8n Node
π―
Next Step
> Ready. Type your expression below and click "Check Answer" to run the node.
Incoming Payload / Data:
{
"attachments": ["invoice.pdf", "photo.png"]
}
$json.attachments.
βοΈ Your expression is executed against test data β any correct solution passes. +10 XP
β Solution & explanation
$json.attachments.length
Output: 2
On arrays,
length returns the number of elements. An empty array returns 0.π‘ Pro tip: n8n adds .isEmpty() and .isNotEmpty() to arrays for readable IF conditions.