SPLIT node - help

Though I am open to alternate nodes to do this.

(Actually I am now thinking this is not the right node for this job, but.....)

I have a message payload (example) 123

I want to split it into 3 messages: 1 2 and 3.

I'm not up on node-red's asynchronous operations, but it may not be needed.

Oh, Specifications for the function:
3 digits. Numbers.
Must be 3 numbers long.
Leading 0 must be sent. (Kinda given if 3 digits)
A nominal delay between messages being sent out.

With function node maybe like this

let digits = msg.payload.toString().split('');
let realDigits = digits.map(Number)

function sendOut(digit){
    node.send({payload:digit})
}

realDigits.forEach(sendOut)

And then add delay node after function node and adjust the delay between messages as needed.

1 Like

I'm happy with that.

I was messing around with:

var y = 0;
var z = 0;
var x = msg.payload;

y = parseInt(x / 100);
msg.payload = y;
node.send(msg);
x = x - (y * 100);

msg.payload = x

node.send(msg);


msg.payload = "test";

return msg;

Yeah, the test isn't needed, but just to see progress.

So I was:
int(/100) -- send result
modify
int(/10) -- send result
modify
send last digit.

But yours seems nicer.

Thanks.

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