Files
n8n-docs/docs/code-examples/javascript-functions/number-items-last-node.md
2023-07-18 15:33:16 +01:00

511 B

contentType
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.

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.

[
  {
    "results": 8
  }
]