Hello,
Quite new to node-red but have a bit of a confusing thing that i would like to have clarification from more experienced node-red developers.
I have a function which i would like to use to return an array of objects:
var outputMsg = [];
testiObject = {
“name”:"",
“value”:""
};
var testName = [“works”,“yes”,“no”];
var testValue = [1,2,3];
test1.name = testName[0];
test1.value = testValue[0];
test2.name = testiName[1];
test2.value = testiValue[1];
What i would like to do now is to push test1 and test2 to to outputMsg and then return the array of 2 objects as a result:
outputMsg.push(test1);
outputMsg.push(test2);
return [ outputMsg ];
Now for some reason when i pass outputMsg to debug node the result is:
{“name”:“yes”,“value”:2,"_msgid":“b993db05.6c75c8”}
{“name”:“yes”,“value”:2,"_msgid":“b993db05.6c75c8”}
As it should naturally be:
{“name”:“works”,“value”:1,"_msgid":“b993db05.6c75c8”}
{“name”:“yes”,“value”:2,"_msgid":“b993db05.6c75c8”}
Can someone please explain to me why this happens and what am doing wrong here?
I know that i could do this correctly like this:
outputMsg.push({payload:{name:test1.name, value:test1.value}});
outputMsg.push({payload:{name:test2.name, value:test2.value}});
return [ outputMsg ];
But i would like to know what goes wrong with trying to push objects test1 and test2 to outputMsg array?
Thank you if you can find time to answer this thing that i just can’t get my head around to.