I get a JSON variable with sequentially numbered objects, and need to loop through it to pull out some data.
In the past, I've had success with ["name" + i], but NR is calling it an unknown object in this case.
Anyone have an idea how I can iterate through this?
var targets = flow.get('targets');
var unitCount = Object.keys(targets).length;
var position = " ";
for (i = 1; i < unitCount; i++) {
position = 'xds' + i;
msg.ip = targets.position.IP;
msg.label = targets.position.Unit;
msg.position = position;
msg.index = i;
node.send(msg);
}
msg.targets = targets;
msg.vars = targets.length;
return msg;
This is the JSON data entered to the flow variable:
{
"xds1": {
"IP": "10.X.X.X",
"Unit": "R1"
},
"xds2": {
"IP": "10.X.X.X",
"Unit": "S1"
},
"xds3": {
"IP": "10.X.X.X",
"Unit": "S2"
},
"xds4": {
"IP": "10.X.X.X",
"Unit": "A1"
},
"xds5": {
"IP": "10.X.X.X",
"Unit": "A2"
}
}