My nodered has problem

a = 0;
while(a<=msg.payload.length){
if(msg.payload[a].ID == "D20A485C"){
msg.payload = {
"NAME" : msg.payload[a].NAME
};
}
}a++;

let a = 0;
while(a<=msg.payload.length){
  if(msg.payload[a].ID == "D20A485C"){
    msg.payload = {
     "NAME" : msg.payload[a].NAME
    };
    break;
  }
  a++;
}
2 Likes

Here is a much better, more modern way and avoids the risk of an infinite loop.

const entry = msg.payload.find(e=>e.ID == "D20A485C")

if (entry) {
  msg.payload = { "NAME" : entry.NAME };
  return msg
}
1 Like

Thank you so muchhhh...it really help

Then, how to stop it after checking all the file...
I don't want it to return msg[not found] after check every column.

because it return like this, if the data not found

it will return TypeError : Cannot read properties of undefined (reading 'ID')

Difficult to tell from a screenshot an no sample data.

Can you select the bunch of related nodes & export the flow (CTRL+E) and paste the copied flow into a code block.
I will also need some sample data of the CSV (it can be fake but must be correct format)

1 Like

Can we reply a message from telegram bot that end with _ (underscore)
Im trying to make this because each msg.payload could be different

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