n8n LabBeginner
Get the Last Element of an Array in n8n
A status history array always has the current status at the end.
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:
{
"history": ["created", "paid", "shipped"]
}
$json.history
βοΈ Your expression is executed against test data β any correct solution passes. +10 XP
β Solution & explanation
$json.history.at(-1)
Output: shipped
at(-1) returns the last element; at(-2) the second to last. The classic way is [array.length - 1]. n8n also adds a .last() helper.π‘ Pro tip: Square brackets don't support negative numbers β history[-1] returns undefined.
Also accepted: .last(), [$json.history.length - 1]