# How to do a simple sum of two msgs which are arrays

**URL:** <https://discourse.nodered.org/t/how-to-do-a-simple-sum-of-two-msgs-which-are-arrays/5675>\
**Category:** General\
**Created:** [11 December 2018 13:16 UTC](https://discourse.nodered.org/t/how-to-do-a-simple-sum-of-two-msgs-which-are-arrays/5675 "2018-12-11T13:16:59Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [11 December 2018 13:35 UTC](https://discourse.nodered.org/t/how-to-do-a-simple-sum-of-two-msgs-which-are-arrays/5675/4 "2018-12-11T13:35:06Z")

</div>

> [@elchmo](#):
>
> So that means I can't get an array c as sum out of a and b?

I described how to do it. Join the arrays and use a Function node to sum them. Is that not what you want?

```auto
[{"id":"8c61ff89.907a1","type":"inject","z":"24d928f3.3c58f8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":340,"wires":[["b0a5b776.cc0ec8","1d512dac.dcf892"]]},{"id":"b0a5b776.cc0ec8","type":"change","z":"24d928f3.3c58f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[1,2,3,4]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":320,"wires":[["4f2d89ed.bacd88"]]},{"id":"1d512dac.dcf892","type":"change","z":"24d928f3.3c58f8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[5,6,7,8]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":360,"wires":[["4f2d89ed.bacd88"]]},{"id":"b4284113.82a9b","type":"function","z":"24d928f3.3c58f8","name":"","func":"\nvar result = [];\nmsg.payload[0].forEach(function(v,i) {\n result.push(v+msg.payload[1][i]); \n});\nmsg.payload = result;\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":340,"wires":[["fad8c15.2e5684"]]},{"id":"fad8c15.2e5684","type":"debug","z":"24d928f3.3c58f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":810,"y":340,"wires":[]},{"id":"4f2d89ed.bacd88","type":"join","z":"24d928f3.3c58f8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":550,"y":340,"wires":[["b4284113.82a9b"]]}]

```

(Please read this post about sharing flows on the forum: [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506))

---

_[View the full topic](https://discourse.nodered.org/t/how-to-do-a-simple-sum-of-two-msgs-which-are-arrays/5675)._
