Display Only Value Fields From The Msg.payload In Node Red
I am working on node red (SNMP). When I deploy, I have the output below: [ { 'oid': '1.3.6.1.2.1.10.21.1.2.1.1.2.1.26', 'type': 2, 'value': 104, 'tstr': 'Integer' }, { 'oid': '1
Solution 1:
The problem is that your for
loop is modifying msg.payload
on each iteration - and because it is doing a +=
it is turning it into a String. That means the second time through the loop, msg.payload
is no longer the object it was at the start so the Object.keys
call fails.
You should build up your result in a new variable and set msg.payload
at the end:
var result = [];
var keys = Object.keys(msg.payload);
for(var i =0; i<keys.length;i++)
{
result.push(msg.payload[keys[i]].value);
}
// At this point, result is an array of the values you want
// You can either return it directly with:
// msg.payload = result;
// or, if you want a string representation of the values as a
// comma-separated list:
// msg.payload = result.join(", ");
return msg;
Post a Comment for "Display Only Value Fields From The Msg.payload In Node Red"