Integer out of array

Hello everyone, i would like to get this variable from the array as an integer but i cant get it out as an int.

image

[{"id":"e19970ec95026bbc","type":"function","z":"a41e06f48b88f632","name":"rotate and rename","func":"const rotated = {\n SERVICELOCATIONID: [],\n SERVICELOCATIONUUID: [],\n NAAM_SERVICELOCATION: [],\n\n\n}\n\n\nconst APIdata = msg.payload.serviceLocations;\nfor (var i = 0; i < APIdata.length; i++) {\n rotated.SERVICELOCATIONID[i] = APIdata[i].serviceLocationId\n rotated.SERVICELOCATIONUUID[i] = APIdata[i].serviceLocationUuid\n rotated.NAAM_SERVICELOCATION[i] = APIdata[i].name\n}\n\nmsg.payload = rotated;\nglobal.set('servicelocation',rotated)\n\nvar msg1 = { payload: rotated.SERVICELOCATIONID };\n\nreturn [msg,msg1];\n\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":930,"y":260,"wires":[["afdbe1dfe8e62ed3"],[]]}]

Which one????

1 Like

image

Feed the incoming message into a debug node and see what it shows.

1 Like

imageI get it out as an array ... i want it as just an integer

I presume that is from this line in your function
var msg1 = { payload: rotated.SERVICELOCATIONID };
If so then you want
var msg1 = { payload: rotated.SERVICELOCATIONID[0] };

1 Like

From reading the code in your flow from the function node I think you have the variable both in msg and in msg1. Let's take what you have in msg1.

I would do something like this but it will just pick the first vaalue in the resulting array. If you have more values you have to loop through the array (next step if this works):

var msg1 = { payload: Number(rotated.SERVICELOCATIONID[0]) };

And what if i would like to call that variabele in another node (another functionblock thats not coppled) , is that possible to ?

Just pass the msg1 to the next node and do the stuff there

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.