# Split a variable!

**URL:** <https://community.n8n.io/t/split-a-variable/333>\
**Category:** Questions\
**Created:** [November 1, 2019, 7:52pm UTC](https://community.n8n.io/t/split-a-variable/333 "2019-11-01T19:52:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mooghermez](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mooghermez/32/26_2.png) [@mooghermez](https://community.n8n.io/u/mooghermez)\
**Post date:** [November 1, 2019, 7:52pm UTC](https://community.n8n.io/t/split-a-variable/333/1 "2019-11-01T19:52:37Z")

</div>

Hi dear friends  
In my case:  
I set a variable from my webhook by “set node”:  
myvar = my\_name\_is\_meysam\_001

I want to split “myvar” by “\_” and split it to 5 new variable like these:  
var1 = my  
var2 = name  
var3 = is  
var4 = meysam  
var5 = 001  
and finally use them in my next nodes.

Can anyone help me how can do this please?  
Best regards;

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [November 1, 2019, 8:13pm UTC](https://community.n8n.io/t/split-a-variable/333/2 "2019-11-01T20:13:52Z")

</div>

You can split them like this:

---

<div class="post-metadata">

**Author:** ![Damian\_K](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/damian_k/32/2586_2.png) [@Damian\_K](https://community.n8n.io/u/Damian_K)\
**Post date:** [January 29, 2021, 12:19pm UTC](https://community.n8n.io/t/split-a-variable/333/3 "2021-01-29T12:19:18Z")

</div>

Is there any way of doing this but instead of returning it to the same item duplicating the item with the new data?

Example:

Names: John & Bob  
Right now split would be Name1=John Name2=Bob

I would want

Item 1: ID: 1 Names: John  
Item 2: ID: 1 Names: Bob

Would that be possible?

---

<div class="post-metadata">

**Author:** ![RicardoE105](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ricardoe105/32/550_2.png) [@RicardoE105](https://community.n8n.io/u/RicardoE105)\
**Post date:** [January 29, 2021, 5:00pm UTC](https://community.n8n.io/t/split-a-variable/333/4 "2021-01-29T17:00:04Z")

</div>

Check the example below:

```
{
  "nodes": [
    {
      "parameters": {},
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "names",
              "value": "John_Bob"
            }
          ]
        },
        "options": {}
      },
      "name": "Set",
      "type": "n8n-nodes-base.set",
      "typeVersion": 1,
      "position": [
        610,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "const results = [];\nconst names = items[0].json.names.split('_');\n\nfor (const[index, name] of names.entries()) {\n results.push({ json: { id: index, name: name } })\n}\n\nreturn results;\n\n\n"
      },
      "name": "Function",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        840,
        300
      ]
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "Set",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set": {
      "main": [
        [
          {
            "node": "Function",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Damian\_K](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/damian_k/32/2586_2.png) [@Damian\_K](https://community.n8n.io/u/Damian_K)\
**Post date:** [January 29, 2021, 6:03pm UTC](https://community.n8n.io/t/split-a-variable/333/5 "2021-01-29T18:03:10Z")

</div>

Hmm, That does indeed return the 2 names but i ment more as in it duplicates the original row that came in so all the original data is included and the id doesnt change

Hmm, I think i got this to work with a merge node in Multiplex mode to merge the results back together
