I have a function node in node-red to output messages to the next node based on a number input it receives set up as follows:
var cards = msg.payload.cards;
var controller = msg.payload.deviceId;
for (let i = 1; i <= cards; i++) {
msg.payload = {"deviceId": controller, "index": i};
node.send(msg);
};
return msg;
The input to the cards variable is for example 2 but returns three messages. Its is outputing i as 1,2,2 not just 1,2 as required
I’m think this is a misunderstanding of the operators on my part but can’t work out why. I have tried numerous examples and explanations from online research but can’t work out a solution. I have tried changing the initial value of i to zero or two but this doesn’t resolve the issue. I have also tried using just less than as the operator but this only returns 1.