# Iterating CSV msg.payload array

**URL:** <https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478>\
**Category:** General\
**Created:** [12 September 2019 18:26 UTC](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478 "2019-09-12T18:26:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rchandrashekar](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@rchandrashekar](https://discourse.nodered.org/u/rchandrashekar)\
**Post date:** [12 September 2019 18:26 UTC](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478/1 "2019-09-12T18:26:43Z")

</div>

How can iterate the msg.payload Object array.

I have a message array as below from the CSV file, how can i have a function to iterate.

Regds  
Rahul.

[{"Sensor\_Value":"0-200","Computed\_Value":10},{"Sensor\_Value":"200-300","Computed\_Value":20},{"Sensor\_Value":"300-400","Computed\_Value":30},{"Sensor\_Value":"400-500","Computed\_Value":40},{"Sensor\_Value":"500-600","Computed\_Value":50},{"Sensor\_Value":"600-700","Computed\_Value":60},{"Sensor\_Value":"700-800","Computed\_Value":70},{"Sensor\_Value":"800-900","Computed\_Value":80}]

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [12 September 2019 18:27 UTC](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478/2 "2019-09-12T18:27:18Z")

</div>

Split node, do actions, join node. It’s a common topic, do a forum search for loops.

---

<div class="post-metadata">

**Author:** ![rchandrashekar](https://avatars.discourse-cdn.com/v4/letter/r/b5a626/32.png) [@rchandrashekar](https://discourse.nodered.org/u/rchandrashekar)\
**Post date:** [12 September 2019 18:30 UTC](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478/3 "2019-09-12T18:30:37Z")

</div>

I have searched, but i am not able to find any answer.  
It would be great if you can help with this example.

Regds  
Rahul.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 September 2019 18:55 UTC](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478/4 "2019-09-12T18:55:52Z")

</div>

You can iterate in a function node using JavaScript (Google JavaScript iterate array) or you can use a Split node to split it into a sequence of messages. So what to do depends on exactly what you are trying to achieve.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [12 September 2019 19:22 UTC](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478/5 "2019-09-12T19:22:09Z")

</div>

Though the CSV node can send individual messages rather than an array so you may not need to iterate

---

<div class="post-metadata">

**Author:** ![clickworkorange](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/clickworkorange/32/12109_2.png) [@clickworkorange](https://discourse.nodered.org/u/clickworkorange)\
**Post date:** [14 September 2019 08:23 UTC](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478/6 "2019-09-14T08:23:34Z")

</div>

> [@Iterating CSV msg.payload array](https://discourse.nodered.org/t/iterating-csv-msg-payload-array/15478/3):
>
> I have searched, but i am not able to find any answer. It would be great if you can help with this example. Regds Rahul.

Try something like this:  
 ![Screenshot_2019-09-14_09-20-44](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/5/53effefce20df68b28b6053601874bf203eab006.png)

```auto
[
    {
        "id": "88c9e740.7493a",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "6104f99d.5f512",
        "type": "inject",
        "z": "88c9e740.7493a",
        "name": "",
        "topic": "",
        "payload": "[{\"Sensor_Value\":\"0-200\",\"Computed_Value\":10},{\"Sensor_Value\":\"200-300\",\"Computed_Value\":20},{\"Sensor_Value\":\"300-400\",\"Computed_Value\":30},{\"Sensor_Value\":\"400-500\",\"Computed_Value\":40},{\"Sensor_Value\":\"500-600\",\"Computed_Value\":50},{\"Sensor_Value\":\"600-700\",\"Computed_Value\":60},{\"Sensor_Value\":\"700-800\",\"Computed_Value\":70},{\"Sensor_Value\":\"800-900\",\"Computed_Value\":80}]",
        "payloadType": "json",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 210,
        "y": 180,
        "wires": [
            [
                "d0064cb2.5e291"
            ]
        ]
    },
    {
        "id": "d0064cb2.5e291",
        "type": "split",
        "z": "88c9e740.7493a",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 340,
        "y": 180,
        "wires": [
            [
                "3e0315bb.c7530a"
            ]
        ]
    },
    {
        "id": "3e0315bb.c7530a",
        "type": "function",
        "z": "88c9e740.7493a",
        "name": "Do Something",
        "func": "var newValue = msg.payload.Computed_Value * 10;\nmsg.payload.Computed_Value = newValue;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 500,
        "y": 180,
        "wires": [
            [
                "95babbd3.b36c48"
            ]
        ]
    },
    {
        "id": "f7e4eef1.003028",
        "type": "debug",
        "z": "88c9e740.7493a",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 830,
        "y": 180,
        "wires": []
    },
    {
        "id": "95babbd3.b36c48",
        "type": "join",
        "z": "88c9e740.7493a",
        "name": "",
        "mode": "auto",
        "build": "string",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": false,
        "timeout": "",
        "count": "",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 670,
        "y": 180,
        "wires": [
            [
                "f7e4eef1.003028"
            ]
        ]
    }
]

```
