Add variable to function

I have a function node that takes in an array and spits out each object as a seperate message. This works 100% like it should:

for (var i = 0; i < msg.payload.length; i++) {
 var newMsg = {};
 newMsg.payload = msg.payload[i];
 node.send(newMsg);
}
return null;

Up until this point the message with the array of objects has a msg.prefix that is removed when the message passes through the function node. The value of msg.prefix is dynamic and can vary with each message.

I want to re-add msg.prefix as part of the function so that each separate message includes msg.prefix with the correct value when it comes back out of the function node.

So take the input and re-add it inside. Anyone know how?

Unless I misunderstand the requirement, all you need is newMsg.prefix = msg.prefix;

That worked perfectly. For anyone wondering in the future, this is the new code:

for (var i = 0; i < msg.payload.length; i++) {
 var newMsg = {};
 newMsg.payload = msg.payload[i];
 newMsg.prefix = msg.prefix;
 node.send(newMsg);
}
return null;

Have you tried feeding it through a Split node instead of your function? I suspect it will do what you want.