Iterating CSV msg.payload array

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}]

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

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.

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.

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

2 Likes

Try something like this:
Screenshot_2019-09-14_09-20-44

[
    {
        "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"
            ]
        ]
    }
]