mirror of
https://github.com/n8n-io/n8n-docs.git
synced 2026-03-27 17:38:40 +07:00
67 lines
726 B
Markdown
67 lines
726 B
Markdown
---
|
|
contentType: howto
|
|
---
|
|
|
|
# Get number of items returned by the previous node
|
|
|
|
To get the number of items returned by the previous node:
|
|
|
|
=== "JavaScript"
|
|
|
|
```js
|
|
if (Object.keys(items[0].json).length === 0) {
|
|
return [
|
|
{
|
|
json: {
|
|
results: 0,
|
|
}
|
|
}
|
|
]
|
|
}
|
|
return [
|
|
{
|
|
json: {
|
|
results: items.length,
|
|
}
|
|
}
|
|
];
|
|
```
|
|
|
|
The output will be similar to the following.
|
|
|
|
```json
|
|
[
|
|
{
|
|
"results": 8
|
|
}
|
|
]
|
|
```
|
|
=== "Python"
|
|
```python
|
|
if len(items[0].json) == 0:
|
|
return [
|
|
{
|
|
"json": {
|
|
"results": 0,
|
|
}
|
|
}
|
|
]
|
|
else:
|
|
return [
|
|
{
|
|
"json": {
|
|
"results": items.length,
|
|
}
|
|
}
|
|
]
|
|
```
|
|
The output will be similar to the following.
|
|
|
|
```json
|
|
[
|
|
{
|
|
"results": 8
|
|
}
|
|
]
|
|
```
|