ramon74
ramon74

Reputation: 115

Node-Red. Get items from object array

I am working in node-red program and I use an OPCUA node that returns in the payload an array of objects.

enter image description here

I need to get some variables of the objects, for example, the nodeId of the item; and I try with the next format:

var newMsg = { payload: msg.payload[0].item.nodeId };
return newMsg;

But it does not work.I can see the error "Error: invalid identifierType in NodeId : 2" I tried a lot of formats but I do not find the correct way.

Do you know How I could get the data of the array of objects?

Thanks.

Upvotes: 0

Views: 9810

Answers (1)

hardillb
hardillb

Reputation: 59751

With the newer versions of Node-RED (after v0.19 iirc) you can get the path to a value from the debug sidebar by placing the mouse over and clicking on the option that pops up.

enter image description here

The >_ icon copies the path to the object (relative to selection in the debug node, so normally msg.payload). In the example payload[0].foo.

This can be used in a function node as msg.payload[0].foo

Upvotes: 2

Related Questions