# Msg.topic manipilation of output of a function node

**URL:** <https://discourse.nodered.org/t/msg-topic-manipilation-of-output-of-a-function-node/43236>\
**Category:** General\
**Created:** [26 March 2021 15:34 UTC](https://discourse.nodered.org/t/msg-topic-manipilation-of-output-of-a-function-node/43236 "2021-03-26T15:34:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [26 March 2021 15:34 UTC](https://discourse.nodered.org/t/msg-topic-manipilation-of-output-of-a-function-node/43236/1 "2021-03-26T15:34:35Z")

</div>

A newbie question.... Again....

I have a function node that has a few outputs, what is the correct way of setting a different topic for a particular output?

ie:

return [{payload:0}, {payload:1}];

Sets the payloads for the outputs.... How do I set the topics (individually) for them too?

Tia  
Ed

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 March 2021 15:50 UTC](https://discourse.nodered.org/t/msg-topic-manipilation-of-output-of-a-function-node/43236/2 "2021-03-26T15:50:10Z")

</div>

> [@eddee54455](#):
>
> I have a function node that has a few outputs, what is the correct way of setting a different topic for a particular output?
> 
> ie:
> 
> return [{payload:0}, {payload:1}];

`return [{topic: "topic1", payload:0}, {topic: "topic2", payload:1}];`

Its just an object property.

A tiny bit of JS training around objects and arrays would help you greatly here. so here goes...

#### long hand version...

```javascript
var msg1 = {}; //create an empty object
msg1.topic = "topic1"; //add a topic property
msg1.payload = 0; //add a payload property

var msg2 = {};//create an empty object
msg2.topic = "topic2";//add a topic property
msg2.payload = 1; //add a payload property

return [msg1, msg2];

```

#### another version...

```javascript
var msg1 = {
  topic : "topic1",
  payload : 0
};

var msg1 = {
  topic : "topic2",
  payload : 1
};

return [msg1, msg2];

```

#### One more...

```javascript
var messages = []; //an empty array
messages.push( { topic : "topic1", payload : 0 } ); //push an object into the array
messages.push( { topic : "topic2", payload : 1 } ); //push an object into the array
return messages; //return the array

```

hopefully that helps you understand some things?

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [26 March 2021 15:53 UTC](https://discourse.nodered.org/t/msg-topic-manipilation-of-output-of-a-function-node/43236/3 "2021-03-26T15:53:33Z")

</div>

@Steve-Mcl

Indeed it does!!

Thank you yet again!!

Ed

---

<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:** [9 April 2021 15:54 UTC](https://discourse.nodered.org/t/msg-topic-manipilation-of-output-of-a-function-node/43236/4 "2021-04-09T15:54:10Z")

</div>

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