# Integer out of array

**URL:** <https://discourse.nodered.org/t/integer-out-of-array/58980>\
**Category:** General\
**Created:** [25 February 2022 13:44 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980 "2022-02-25T13:44:32Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [25 February 2022 13:44 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/1 "2022-02-25T13:44:32Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/5/b53f561b8f14dec41894faddc0f7746afe7f5afd.png)

`[{"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"],[]]}]`

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [25 February 2022 13:55 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/2 "2022-02-25T13:55:02Z")

</div>

> [@Olivia](#):
>
> get this variable

Which one????

---

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [25 February 2022 13:55 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/3 "2022-02-25T13:55:52Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5fee13e39cf72cebffc0f54f259c52746ed73233.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 February 2022 14:00 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/4 "2022-02-25T14:00:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [25 February 2022 14:02 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/5 "2022-02-25T14:02:22Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/644b083d87b85c451e2d9af9bed04a4df0b6972f.png)I get it out as an array ... i want it as just an integer

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 February 2022 14:08 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/6 "2022-02-25T14:08:57Z")

</div>

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] };`

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [25 February 2022 14:09 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/7 "2022-02-25T14:09:03Z")

</div>

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]) };`

---

<div class="post-metadata">

**Author:** ![Olivia](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/olivia/32/57161_2.png) [@Olivia](https://discourse.nodered.org/u/Olivia)\
**Post date:** [25 February 2022 14:11 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/8 "2022-02-25T14:11:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [25 February 2022 14:11 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/9 "2022-02-25T14:11:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [11 March 2022 14:12 UTC](https://discourse.nodered.org/t/integer-out-of-array/58980/10 "2022-03-11T14:12:09Z")

</div>

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