admin管理员组文章数量:1406016
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.
本文标签: If statement in Node red (javascript)Stack Overflow
版权声明:本文标题:If statement in Node red (javascript) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744360024a2602497.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论