# Split String to Array

**URL:** <https://community.n8n.io/t/split-string-to-array/8872>\
**Category:** Questions\
**Created:** [November 3, 2021, 2:13pm UTC](https://community.n8n.io/t/split-string-to-array/8872 "2021-11-03T14:13:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mulen](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Mulen](https://community.n8n.io/u/Mulen)\
**Post date:** [November 3, 2021, 2:13pm UTC](https://community.n8n.io/t/split-string-to-array/8872/1 "2021-11-03T14:13:16Z")

</div>

Hello.

Can someone help me split this

```auto

[
{
"values": "111, 222, 333"
}
] 

```

into this

```auto

[
{
"values": "111"
},
{
"values": "222"
},
{
"values": "333"
}
] 

```

---

<div class="post-metadata">

**Author:** ![MutedJam](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/mutedjam/32/70851_2.png) [@MutedJam](https://community.n8n.io/u/MutedJam)\
**Post date:** [November 3, 2021, 2:19pm UTC](https://community.n8n.io/t/split-string-to-array/8872/3 "2021-11-03T14:19:27Z")

</div>

You could do so via a short JS snippet using [String.split()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split).

> **Example Workflow**
>

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/b/b5909cbd0feb90013b29a2077ecdafdcdb5acc53.png)

This example would also work for multiple input items with an array in each. If you ever only have one input item you can simplify it a bit as you wouldn’t need to loop through multiple items.

---

<div class="post-metadata">

**Author:** ![Mulen](https://avatars.discourse-cdn.com/v4/letter/m/5fc32e/32.png) [@Mulen](https://community.n8n.io/u/Mulen)\
**Post date:** [November 3, 2021, 2:35pm UTC](https://community.n8n.io/t/split-string-to-array/8872/4 "2021-11-03T14:35:10Z")

</div>

Thank you very much.

It works.

---

<div class="post-metadata">

**Author:** ![physx911](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/physx911/32/23837_2.png) [@physx911](https://community.n8n.io/u/physx911)\
**Post date:** [December 31, 2021, 12:16pm UTC](https://community.n8n.io/t/split-string-to-array/8872/5 "2021-12-31T12:16:55Z")

</div>

Thank you for the solution. Expanding @Mulen example, I have a query, is there a way to add other keys to the same referenced “values” and club them under their respective object?

```auto
[
{
"values": "111, 222, 333",
"names": "A, B, C"
}
] 

```

into this:

```auto
[
{
"value": "111",
"name": "A"
},
{
"value": "222",
"name": "B"
},
{
"value": "333",
"name": "C"
}
]

```

---

<div class="post-metadata">

**Author:** ![Shirobachi](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shirobachi/32/37882_2.png) [@Shirobachi](https://community.n8n.io/u/Shirobachi)\
**Post date:** [December 31, 2021, 2:07pm UTC](https://community.n8n.io/t/split-string-to-array/8872/6 "2021-12-31T14:07:53Z")

</div>

Check it out:

---

<div class="post-metadata">

**Author:** ![physx911](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/physx911/32/23837_2.png) [@physx911](https://community.n8n.io/u/physx911)\
**Post date:** [January 1, 2022, 2:31pm UTC](https://community.n8n.io/t/split-string-to-array/8872/7 "2022-01-01T14:31:57Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![physx911](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/physx911/32/23837_2.png) [@physx911](https://community.n8n.io/u/physx911)\
**Post date:** [January 21, 2022, 8:13pm UTC](https://community.n8n.io/t/split-string-to-array/8872/8 "2022-01-21T20:13:43Z")

</div>

Hello @Shirobachi

Is there a way to call the items of _values_ and _names_ that are to be split from a remote node (node not connected in order)?

```auto
let myValues = [];
let myNames = [];

for (item of items) {
  myValues.push(...item.json.values.split(','));
  myNames.push(...item.json.names.split(','));
}

let res = [];

// use max of both
for(i=0; i<myNames.length; i++){
  res.push(
    {
      "json": {
        "value": myValues[i],
        "name": myNames[i]
      }
    }
  )
}

return res

```

---

<div class="post-metadata">

**Author:** ![Shirobachi](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/shirobachi/32/37882_2.png) [@Shirobachi](https://community.n8n.io/u/Shirobachi)\
**Post date:** [January 22, 2022, 8:22am UTC](https://community.n8n.io/t/split-string-to-array/8872/9 "2022-01-22T08:22:12Z")

</div>

I think it is not possible, but maybe someone more experienced will confirm this.

For sure, you can call value from other node if there are connected like this:
