Skip to content

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 Function node.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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.

1
2
3
4
5
[
  {
    "results": 8
  }
]