I'm trying to evaluate a value in node red :
from the join node I'm getting the following:
so what I'm trying to do in the function is to check the 1. sent value:
var payload = msg.payload;
if (msg.payload[0] === "0" ){
msg.payload =0;
} else {
msg.payload = 1;
}
//msg.payload = payload[0];
return msg;
So my question why am I getting the if statement is false ?
thanks for any hint
I'm trying to evaluate a value in node red :
from the join node I'm getting the following:
so what I'm trying to do in the function is to check the 1. sent value:
var payload = msg.payload;
if (msg.payload[0] === "0" ){
msg.payload =0;
} else {
msg.payload = 1;
}
//msg.payload = payload[0];
return msg;
So my question why am I getting the if statement is false ?
thanks for any hint
Share Improve this question asked Oct 8, 2018 at 8:53 EngineEngine 5,43222 gold badges93 silver badges169 bronze badges1 Answer
Reset to default 3Not sure what you are trying to check but checking the value of the payload property can be done as follows:
if(typeof msg.payload === "object"){
if(msg.payload[0].value === 0) { // Use "0" if this value is a string, but I guess not by inspecting your data.
// Your code
} else {
// Other code
}
}
else {
// msg.payload is not an array
}
According to your data, you have two situations, either msg.payload
is an array or either it is a value.