Temporary Array?

Hello,

I’ve a situation that I can’t solve without relying on external sources (files, databases), but maybe is it possible.

The situation:
I’ve several items that need to be validated and if the validation passes, added to the array for later processing

…in other terms the resultArray should be temporary while SplitinBatches is running and then passed to outResultArray. Is it possible?

Example code

{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        180,
        240
      ]
    },
    {
      "parameters": {
        "functionCode": "return [\n  {\n    json: {\n      url: 'https://one/',\n      data: 0,\n    }\n  },\n    {\n    json: {\n      url: 'https://two/',\n      data: 0,\n    }\n  },\n      {\n    json: {\n      url: 'https://three/',\n      data: 1,\n    }\n  },\n        {\n    json: {\n      url: 'https://four/',\n      data: 0,\n    }\n  },\n          {\n    json: {\n      url: 'https://five/',\n      data: 1,\n    }\n  },\n            {\n    json: {\n      //empty json to break out\n    }\n  }\n]\n\n"
      },
      "name": "Mockup data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        420,
        240
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "name": "SplitInBatches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 1,
      "position": [
        650,
        240
      ]
    },
    {
      "parameters": {},
      "name": "resultArray",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1240,
        490
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [],
          "number": [
            {
              "value1": "={{$node[\"SplitInBatches\"].json[\"data\"]}}",
              "operation": "equal"
            }
          ]
        }
      },
      "name": "Several checks",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        950,
        510
      ]
    },
    {
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{$node[\"SplitInBatches\"].context[\"noItemsLeft\"]}}",
              "value2": true
            }
          ]
        }
      },
      "name": "IF not end",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        240
      ]
    },
    {
      "parameters": {},
      "name": "doSomeOtherStuff",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1290,
        170
      ]
    },
    {
      "parameters": {},
      "name": "outResultArray",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1090,
        170
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Mockup data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mockup data": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "SplitInBatches": {
      "main": [
        [
          {
            "node": "IF not end",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "resultArray": {
      "main": [
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Several checks": {
      "main": [
        [
          {
            "node": "resultArray",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "SplitInBatches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF not end": {
      "main": [
        [
          {
            "node": "outResultArray",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Several checks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "outResultArray": {
      "main": [
        [
          {
            "node": "doSomeOtherStuff",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

You can access the data from inside the loop outside it and build your array there. You can find an example of it here in the Function-Node named “Merge Data”:

Thanks @jan for showing the way :arrow_upper_right::arrow_lower_right::grinning:

…the answer was right in front of me! :no_mouth:

Glad to hear that it helped! Have fun!