Iteration stops after first loop

I am having some trouble with iteration and for loop. It stops after first loop. Value_Analog has three objects, first is empty (I don't need it). I need this output
image

Code in function. I am triggering it by inject node.

var Value_Analog = global.get('Value_Analog');
var Pasalintasempty = Value_Analog.shift();//pasalinam empty array elementa
let index = 0;

for (let i = 0; i < Value_Analog.length; i++) 
{ 
 msg.payload = ([{[Value_Analog[i].Tag_name]: index}])
   index++;
}
return msg;

No it iterates over all the array and as it does it overwrites msg.payload each time.
Try

msg.payload[i] = {[Value_Analog[i].Tag_name]: i};

No need for index as i is doing the same thing.
[edit] Make sure you define msg.payload as an array before the loop msg.payload = [];

Thank you, it works now.

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