mirror of
https://github.com/n8n-io/n8n-docs.git
synced 2026-03-28 18:08:41 +07:00
37 lines
511 B
Markdown
37 lines
511 B
Markdown
---
|
|
contentType: howto
|
|
---
|
|
|
|
# Get number of items returned by the last node
|
|
|
|
Depending on your use-case, you might want to get the number of items returned by the last node. Use the following snippet in the Code node.
|
|
|
|
```js
|
|
if (Object.keys(items[0].json).length === 0) {
|
|
return [
|
|
{
|
|
json: {
|
|
results: 0,
|
|
}
|
|
}
|
|
]
|
|
}
|
|
return [
|
|
{
|
|
json: {
|
|
results: items.length,
|
|
}
|
|
}
|
|
];
|
|
```
|
|
|
|
The output will then be similar to the following.
|
|
|
|
```js
|
|
[
|
|
{
|
|
"results": 8
|
|
}
|
|
]
|
|
```
|