# Add up numbers in a message

**URL:** <https://discourse.nodered.org/t/add-up-numbers-in-a-message/60034>\
**Category:** General\
**Tags:** function-node\
**Created:** [18 March 2022 12:23 UTC](https://discourse.nodered.org/t/add-up-numbers-in-a-message/60034 "2022-03-18T12:23:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubenbraekman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rubenbraekman/32/58663_2.png) [@rubenbraekman](https://discourse.nodered.org/u/rubenbraekman)\
**Post date:** [18 March 2022 12:23 UTC](https://discourse.nodered.org/t/add-up-numbers-in-a-message/60034/1 "2022-03-18T12:23:01Z")

</div>

Hey I'm a node-red noob, I need to add up the numbers in blue but I'm not sure how.  
It's probable pretty simple.

 ![numbers](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/1/716406522413503b47d4de2a0753d3460795dd3e.png)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [18 March 2022 12:32 UTC](https://discourse.nodered.org/t/add-up-numbers-in-a-message/60034/2 "2022-03-18T12:32:42Z")

</div>

you can use javascipt in a function node, or JSONata in a change node.  
e.g.

```auto
[{"id":"19ebc061.cadb78","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"a\":1,\"b\":2,\"c\":3}","payloadType":"json","x":260,"y":220,"wires":[["594f31a5.0be01","62d55a1a.81300c"]]},{"id":"594f31a5.0be01","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum($$.payload.*)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":200,"wires":[["2855db0a.fae91c"]]},{"id":"62d55a1a.81300c","type":"function","z":"bf9e1e33.030598","name":"","func":"let values = Object.values(msg.payload);\nmsg.payload = values.reduce((a,v) => a+v);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":280,"wires":[["2855db0a.fae91c"]]},{"id":"2855db0a.fae91c","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":740,"y":260,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![rubenbraekman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rubenbraekman/32/58663_2.png) [@rubenbraekman](https://discourse.nodered.org/u/rubenbraekman)\
**Post date:** [18 March 2022 12:44 UTC](https://discourse.nodered.org/t/add-up-numbers-in-a-message/60034/3 "2022-03-18T12:44:32Z")

</div>

I have found a noob way to add them up in the meantime, but thanks for the help!

![solution](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/d/ddea908ed506dd08060d7118078ff31cc3fa861f.png)  
 ![solution 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/3721c6744a190661816ab0765ee88bedec9e079a.png)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 May 2022 12:44 UTC](https://discourse.nodered.org/t/add-up-numbers-in-a-message/60034/4 "2022-05-17T12:44:40Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
