Iterating over multiple arrays

Sorry to be a pain again,
I have used this iterator before and it works ok for one array with multiple objects in it

return items[0].json.objects.map(item => {
  return {
    json: item
  }
});

but how do it get it to do the same when there are multiple arrays with objects in from the previous node.

this only shows the first array [0] of [many-arrays] depending on how many arrays the previous node dumps out.

at the moment only one result comes back and ignores the rest.

Check the example below

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      objects: [\n        {\n          key: 'value'\n        }\n      ]\n    }\n  },\n    {\n    json: {\n      objects: [\n        {\n          key: 'value'\n        }\n      ]\n    }\n  }\n]"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        510,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const results = []\n\nfor (const item of items) {\n  results.push.apply(results, item.json.objects)\n}\n\nconst data = results.map(element => ({ json: element }))\n\nreturn data;"
      },
      "name": "Function1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        730,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Function": {
      "main": [
        [
          {
            "node": "Function1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

This is exactly what was needed, thank you!!

Hey @RedPacketSec!

We have documented similar code snippets that you can refer to. You can find them on the JavaScript Code Snippets page. If there’s any code snippet that you think is helpful and should be added, do let us know :slight_smile: