# Doubts with Array

**URL:** <https://community.n8n.io/t/doubts-with-array/6575>\
**Category:** Questions\
**Tags:** data-transformation, node\
**Created:** [July 1, 2021, 5:49pm UTC](https://community.n8n.io/t/doubts-with-array/6575 "2021-07-01T17:49:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilherme\_Hirsch](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/guilherme_hirsch/32/5105_2.png) [@Guilherme\_Hirsch](https://community.n8n.io/u/Guilherme_Hirsch)\
**Post date:** [July 1, 2021, 5:49pm UTC](https://community.n8n.io/t/doubts-with-array/6575/1 "2021-07-01T17:49:47Z")

</div>

Hey guys!

I’m trying to return items with this structure:

 ![1](https://europe1.discourse-cdn.com/n8n/original/2X/1/1d23a622f39b9fcff0514322ffbceeabe3e9ec85.jpeg)

So that they look like this (outside the array):

 ![2](https://europe1.discourse-cdn.com/n8n/original/2X/4/4fac6e011632fd390f3c4094221b3029eb3f2ab4.jpeg)

---

<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:** [July 1, 2021, 9:33pm UTC](https://community.n8n.io/t/doubts-with-array/6575/2 "2021-07-01T21:33:03Z")

</div>

So you want to map the first picture to the second picture? Is it the first output coming from an HTTP node?

---

<div class="post-metadata">

**Author:** ![Guilherme\_Hirsch](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/guilherme_hirsch/32/5105_2.png) [@Guilherme\_Hirsch](https://community.n8n.io/u/Guilherme_Hirsch)\
**Post date:** [July 2, 2021, 11:10am UTC](https://community.n8n.io/t/doubts-with-array/6575/3 "2021-07-02T11:10:28Z")

</div>

Yes, @RicardoE105, that’s the idea. I generated this data artificially for testing as I have a bigger workflow with xml files.

---

<div class="post-metadata">

**Author:** ![ivov](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/ivov/32/1463_2.png) [@ivov](https://community.n8n.io/u/ivov)\
**Post date:** [July 2, 2021, 11:34am UTC](https://community.n8n.io/t/doubts-with-array/6575/4 "2021-07-02T11:34:58Z")

</div>

If every inner array has a single item, then:

```auto
return items.map(i => ({ json: i.json[0] }));

```

---

<div class="post-metadata">

**Author:** ![Guilherme\_Hirsch](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/guilherme_hirsch/32/5105_2.png) [@Guilherme\_Hirsch](https://community.n8n.io/u/Guilherme_Hirsch)\
**Post date:** [July 2, 2021, 4:03pm UTC](https://community.n8n.io/t/doubts-with-array/6575/5 "2021-07-02T16:03:53Z")

</div>

Thank you very much, @ivov ! Now I understand the structure of the data well.

---

<div class="post-metadata">

**Author:** ![Guilherme\_Hirsch](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/guilherme_hirsch/32/5105_2.png) [@Guilherme\_Hirsch](https://community.n8n.io/u/Guilherme_Hirsch)\
**Post date:** [July 2, 2021, 4:55pm UTC](https://community.n8n.io/t/doubts-with-array/6575/6 "2021-07-02T16:55:54Z")

</div>

One more question arose. And in case the internal array has one more object. How do I return in this structure?

---

<div class="post-metadata">

**Author:** ![Guilherme\_Hirsch](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/guilherme_hirsch/32/5105_2.png) [@Guilherme\_Hirsch](https://community.n8n.io/u/Guilherme_Hirsch)\
**Post date:** [July 3, 2021, 4:12pm UTC](https://community.n8n.io/t/doubts-with-array/6575/7 "2021-07-03T16:12:08Z")

</div>

I’ve been stuck in this second situation for days. Any help is valid.

---

<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:** [July 3, 2021, 8:36pm UTC](https://community.n8n.io/t/doubts-with-array/6575/8 "2021-07-03T20:36:29Z")

</div>

Dude, sorry for the late response. In that case, the function node should look like this:

```auto
const response = []

for (item of items) {
  for (data of item.json) {
    response.push({
      json: data
    })
  }
}
return response

```

> **Example workflow**
>
> ```
> {
> "nodes": [
> {
> "parameters": {},
> "name": "Start",
> "type": "n8n-nodes-base.start",
> "typeVersion": 1,
> "position": [
> -1910,
> 40
> ]
> },
> {
> "parameters": {
> "functionCode": "return [\n {\n json: [\n {\n name: 'ricardp'\n },\n {\n name: 'ricardp'\n }\n]\n },\n {\n json: [\n {\n name: 'ricardp'\n },\n {\n name: 'ricardp'\n }\n]\n }\n]"
> },
> "name": "Function",
> "type": "n8n-nodes-base.function",
> "typeVersion": 1,
> "position": [
> -1650,
> 30
> ]
> },
> {
> "parameters": {
> "functionCode": "const response = []\n\nfor (item of items) {\n for (data of item.json) {\n response.push({\n json: data\n })\n }\n}\nreturn response"
> },
> "name": "Function1",
> "type": "n8n-nodes-base.function",
> "typeVersion": 1,
> "position": [
> -1380,
> 30
> ]
> }
> ],
> "connections": {
> "Start": {
> "main": [
> [
> {
> "node": "Function",
> "type": "main",
> "index": 0
> }
> ]
> ]
> },
> "Function": {
> "main": [
> [
> {
> "node": "Function1",
> "type": "main",
> "index": 0
> }
> ]
> ]
> }
> }
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![Guilherme\_Hirsch](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/guilherme_hirsch/32/5105_2.png) [@Guilherme\_Hirsch](https://community.n8n.io/u/Guilherme_Hirsch)\
**Post date:** [July 4, 2021, 1:13pm UTC](https://community.n8n.io/t/doubts-with-array/6575/9 "2021-07-04T13:13:31Z")

</div>

Wow, @RicardoE105! Your solution worked perfectly well! Thank you so much for everyone’s help!
