# Check state and send to mqtt from multiple array

**URL:** <https://discourse.nodered.org/t/check-state-and-send-to-mqtt-from-multiple-array/6592>\
**Category:** General\
**Created:** [9 January 2019 07:44 UTC](https://discourse.nodered.org/t/check-state-and-send-to-mqtt-from-multiple-array/6592 "2019-01-09T07:44:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![junoprima](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/junoprima/32/63547_2.png) [@junoprima](https://discourse.nodered.org/u/junoprima)\
**Post date:** [9 January 2019 07:44 UTC](https://discourse.nodered.org/t/check-state-and-send-to-mqtt-from-multiple-array/6592/1 "2019-01-09T07:44:09Z")

</div>

Hello i need some help , how to check casenamemax inside any array [0][1][2]........

example if case == 01 send to mqtt ........ with all index data status,imei,casenamemax

or case == 02,03 ...... send

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/66c424538f2c60f3a25d5d6781333a99bd756852.png)

Thank you for reply

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [9 January 2019 07:49 UTC](https://discourse.nodered.org/t/check-state-and-send-to-mqtt-from-multiple-array/6592/2 "2019-01-09T07:49:07Z")

</div>

Use the function node and do it in javascript

---

<div class="post-metadata">

**Author:** ![junoprima](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/junoprima/32/63547_2.png) [@junoprima](https://discourse.nodered.org/u/junoprima)\
**Post date:** [9 January 2019 07:50 UTC](https://discourse.nodered.org/t/check-state-and-send-to-mqtt-from-multiple-array/6592/3 "2019-01-09T07:50:45Z")

</div>

yeah i use it in javascript and i dont know how to write it thx sir

---

<div class="post-metadata">

**Author:** ![junoprima](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/junoprima/32/63547_2.png) [@junoprima](https://discourse.nodered.org/u/junoprima)\
**Post date:** [9 January 2019 08:43 UTC](https://discourse.nodered.org/t/check-state-and-send-to-mqtt-from-multiple-array/6592/4 "2019-01-09T08:43:07Z")

</div>

```
 var l = msg.payload[0].length;

for (var i = 0; i < l; i++) {
   node.send({
        payload: msg.payload[0][i].casenamemax
  });
}
return msg;

```

I try this code can output same as i send before

---

<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:** [9 January 2019 09:27 UTC](https://discourse.nodered.org/t/check-state-and-send-to-mqtt-from-multiple-array/6592/5 "2019-01-09T09:27:27Z")

</div>

The `msg.payload[0][i]` bit is wrong and the length calculation, and also you are returning the original message at the end. Something like this may be better.

```auto
var l = msg.payload.length;
for (var i = 0; i < l; i++) {
   node.send({
        payload: msg.payload[i].casenamemax
  });
}
return null;

```

For the future you can debug your code using `node.warn()`. So after the `var l = ..` line you could have put

```auto
node.warn("l is " + l);

```

and it would have displayed the value of l in the debug pane. By adding warn statements through the code you can find which bit is not working.
