Iterate through items with same name

Hi there,
with the successful “create multiple items” I am stuck again.
Now the items have the same name “color”, when I iterate, only the last item will be used, instead of all of them.
Question: How can I iterate through all color

here is what I did:

{
  "nodes": [
{
  "parameters": {
    "functionCode": "return items[0].json.map(item => { \n  return {\n    json: item,\n  }\n})"
  },
  "name": "Create JSON-items2",
  "type": "n8n-nodes-base.function",
  "position": [
    250,
    840
  ],
  "typeVersion": 1
},
{
  "parameters": {
    "functionCode": "const data = items[0].json[\"color\"];\nconst data_arr = Object.keys(data).map(key => {\n    return data[key]\n})\n\nreturn [{json:data_arr}]"
  },
  "name": "Create array2",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    70,
    840
  ]
},
{
  "parameters": {
    "functionCode": "items[0].json = \n{\n        \"color\": [\n        {\n            \"id\": 1,\n            \"name\": \"blue\",\n        },\n        {\n            \"id\": 2,\n            \"name\": \"red\",\n        }\n        ],\n        \"color\": [\n        {\n            \"id\": 3,\n            \"name\": \"green\",\n        },\n        {\n            \"id\": 4,\n            \"name\": \"yellow\",\n        }\n\n]\n};\nreturn items;"
  },
  "name": "Create Data1",
  "type": "n8n-nodes-base.function",
  "typeVersion": 1,
  "position": [
    -110,
    840
  ]
}
  ],
  "connections": {
"Create array2": {
  "main": [
    [
      {
        "node": "Create JSON-items2",
        "type": "main",
        "index": 0
      }
    ]
  ]
},
"Create Data1": {
  "main": [
    [
      {
        "node": "Create array2",
        "type": "main",
        "index": 0
      }
    ]
  ]
}
  }
}

Sorry do not understand what you mean. Where and for what does only the last one get used and what do you want to do?
By default do nodes normally use all the items and a very very small amount only the first one. I can not think of any node that uses the last one.

Hi @jan,
thank you for the answer. My example did not show the problem I am facing properly, sorry for that.
I get this json as input:

{
        "color": [
        {
            "id": 1,
            "name": "blue",
        },
        {
            "id": 2,
            "name": "red",
        }
        ],
        "color": [
        {
            "id": 3,
            "name": "green",
        },
        {
            "id": 4,
            "name": "yellow",
        }

]
}

And when I iterate through “color”:
only first color will be used.
with this code:

return items[0].json["color"].map(item => { 
  return {
    json: item,
  }
})

here are both as nodes:

{
  "nodes": [
    {
      "parameters": {
        "functionCode": "return items[0].json[\"color\"].map(item => { \n  return {\n    json: item,\n  }\n})"
      },
      "name": "Create JSON-items2",
      "type": "n8n-nodes-base.function",
      "position": [
        90,
        840
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "functionCode": "items[0].json = \n{\n        \"color\": [\n        {\n            \"id\": 1,\n            \"name\": \"blue\",\n        },\n        {\n            \"id\": 2,\n            \"name\": \"red\",\n        }\n        ],\n        \"color\": [\n        {\n            \"id\": 3,\n            \"name\": \"green\",\n        },\n        {\n            \"id\": 4,\n            \"name\": \"yellow\",\n        }\n\n]\n};\nreturn items;"
      },
      "name": "Create Data1",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        -110,
        840
      ]
    }
  ],
  "connections": {
    "Create Data1": {
      "main": [
        [
          {
            "node": "Create JSON-items2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Yes, that as input is simply impossible. Has however less to do with n8n more with JavaScript. Or actually any programming language. The problem is that the first color gets overwritten by the second one as they are in the same object.
Are you sure that you receive the data like that? Because also the Webhook-Node would not be able to display the data like that (for the above reasons).

I understand. I have a node which has a single color object as output, but I call this node with a list of ids, so its generating one object with multiple “color”.
I think, there is an easy solution, but I need to find it by myself.
Thanks again @jan

You are welcome.

Normally it should simply output multiple items of which each has a color property. If that is not “good” for whatever reason, an alternative would be to change “color” to be an array.

Did he mean something like this?