# Question : function node

**URL:** <https://discourse.nodered.org/t/question-function-node/6763>\
**Category:** General\
**Created:** [13 January 2019 21:16 UTC](https://discourse.nodered.org/t/question-function-node/6763 "2019-01-13T21:16:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MPopti0n](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mpopti0n/32/5165_2.png) [@MPopti0n](https://discourse.nodered.org/u/MPopti0n)\
**Post date:** [13 January 2019 21:16 UTC](https://discourse.nodered.org/t/question-function-node/6763/1 "2019-01-13T21:16:17Z")

</div>

Hi,

it maybe is a dumb question but here goes!

My `function node` is reciving a message like this :

```
{
"_msgid":"fd517150.49f97",
"topic":"",
"payload":"Blablabla",
"Appareil":"G102_G008_L308"
} 

```

On the other side of the `function node` I want this ["Appareil" proprety split (variable number) + payload] :

**Msg #1**  
{  
"\_msgid":"fd517150.49f97",  
"topic":"",  
"payload":"Blablabla",  
"Appareil":"G102"  
}  
**Msg #2**  
{  
"\_msgid":"fd517150.49f97",  
"topic":"",  
"payload":"Blablabla",  
"Appareil":"G008"  
}  
**Msg #3**  
{  
"\_msgid":"fd517150.49f97",  
"topic":"",  
"payload":"Blablabla",  
"Appareil":"L308"  
}  
**Msg #..... and so on**

For now i've been able to split the "Appareil" proprety but I can't figure out how to make the payload follow

Inside the `function node` :

```
var outputMsgs = [];
var words = msg.Appareil.split("_");
for (var w in words) {
    outputMsgs.push({Appareil:words[w]})
}
return [outputMsgs];
```

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [13 January 2019 21:52 UTC](https://discourse.nodered.org/t/question-function-node/6763/2 "2019-01-13T21:52:08Z")

</div>

I would use the `map()` function to turn an array of words into an array of msg objects, with each word inside the new msg -- something like this:

```auto
var words = msg.Appareil.split("_");
var outputMsgs = words.map(function(word) {
    return {
        _msgid: msg._msgid,
        topic: msg.topic,
        payload: msg.payload,
        Appareil: word
    };
});
return [outputMsgs];

```

Essentially, you are copying the incoming msg properties (other than Appareil) into a new msg object. Since you are returning an array of length 1, containing an array of N msgs, the new messages will be sent one at a time out of Port #1 -- which sounds like what you are wanting to do.

---

<div class="post-metadata">

**Author:** ![MPopti0n](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mpopti0n/32/5165_2.png) [@MPopti0n](https://discourse.nodered.org/u/MPopti0n)\
**Post date:** [13 January 2019 22:29 UTC](https://discourse.nodered.org/t/question-function-node/6763/3 "2019-01-13T22:29:29Z")

</div>

Thank you so much 🙂 ! It works like a charm!

Sorry for the dumb question but I'm pretty new to this!
