Iterate array value

Hello
I have this kind of result:

[
 {
    "values": [ 
       "000732342",
       "",
       "000731588"
    ]
 }
[

I would like to be able to iterate each of the values and exclude the empty one

Thanks for your help

Hi @fporta, you could use the Item Lists node to split the array inside values into separate items followed by an IF node to filter out the empty field:

Example Workflow
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "return [{\n    json: {\n        \"values\": [\n            \"000732342\",\n            \"\",\n            \"000731588\"\n        ]\n    }\n}]"
      },
      "name": "Set Example Data",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "fieldToSplitOut": "values",
        "options": {}
      },
      "name": "Split Out",
      "type": "n8n-nodes-base.itemLists",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json[\"values\"]}}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "name": "Is Empty?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {},
      "name": "Do Nothing",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1050,
        200
      ]
    },
    {
      "parameters": {},
      "name": "Do Something",
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        1050,
        400
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set Example Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Example Data": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Is Empty?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Empty?": {
      "main": [
        [
          {
            "node": "Do Nothing",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Do Something",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Hope this helps! :slight_smile:

I tried with the itemList but I can’t get anything

et voici l’erreur

Thanks

Have you had a look at the example workflow I posted in my previous message? You can just copy and paste it into your n8n canvas to try it yourself.

In your screenshot, the Item Lists node would require the field name in the Fields To Split Out field rather than an expression. So in the example you have described that’d be values.

Sorry, it’s my fault, my n8n server was down. I’ve just looked at your example, indeed you have to give the value rather than going to look for it in the previous node…
Thank u very much

1 Like

Glad to hear it’s working, thanks so much for confirming!