# How to only pass through a certain part of an array?

**URL:** <https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766>\
**Category:** General\
**Created:** [16 January 2022 21:43 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766 "2022-01-16T21:43:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![haavardbj](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@haavardbj](https://discourse.nodered.org/u/haavardbj)\
**Post date:** [16 January 2022 21:43 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/1 "2022-01-16T21:43:30Z")

</div>

Hi

I have a node sending data from a energy-meter.  
The data that i recieve is delivered like this.  
Delivery 1: an array of data,  
Delivery 2. a given value (1 line of the array)  
Delivery 3: a given value (1 line of the array)

I am using a function node to extract a certain value frome the array:

var o = msg.payload  
msg.payload = o.volt\_L3 / 10  
return msg;

The issue is sthat "delivery nr 2 & 3" does not have the array, therfore the results is "NaN".

The value i try to extract is passed on to a smart-house-system. The "NaN" value is therfore translated in to "0" in the smart-house-system.

What is best-pracsis for only extracting data from the msg. that has the full array, and skipp/not pass on the data from the msg. that doesnt have the full array.

---

<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:** [16 January 2022 22:00 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/2 "2022-01-16T22:00:45Z")

</div>

> [@haavardbj](#):
>
> var o = msg.payload  
> msg.payload = o.volt\_L3 / 10

That will not work if msg.payload is an array. Perhaps you mean a javascript object. I think you had better feed the messages into a debug node and show us what you have actually got.

What node are you using for getting the data?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [16 January 2022 22:10 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/3 "2022-01-16T22:10:02Z")

</div>

> [@haavardbj](#):
>
> The issue is sthat "delivery nr 2 & 3" does not have the array, therfore the results is "NaN".

Are your values coming into the function from separate wires? You might need a `join` node

Show us your flow.

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [17 January 2022 00:38 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/4 "2022-01-17T00:38:17Z")

</div>

You can filter your payload with a switch node, checking if the payload contains an array.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/c/0c4107132a8e4ee64aff58bf878da799716bc938.png)

---

<div class="post-metadata">

**Author:** ![haavardbj](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@haavardbj](https://discourse.nodered.org/u/haavardbj)\
**Post date:** [17 January 2022 18:37 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/5 "2022-01-17T18:37:44Z")

</div>

Hi

This is the debug frome the node ( AMD decoder)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b097410fe496184ff5cbe233d4576f3d800ca303.png)

As you can see from the picture, every 3. messages is the "whole object", the 2 other messages contains onlye the vale "act\_pow\_pos"

Its all beeing "picked upp" trough a USB-adapter..

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/64a9cbb9ab4e1c592eebc3233d8887f4d0ccbe0c.png)

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [17 January 2022 19:58 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/6 "2022-01-17T19:58:02Z")

</div>

Ok then it is not an array which you need to pick out - so you need to filter on a specific property.

```auto
[{"id":"3f247e651403fc6f","type":"switch","z":"cb05e14b.326a9","name":"","property":"payload.meter_ID","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":620,"y":1580,"wires":[[]]}]

```

So only those messages will pass with a valid meter\_ID

---

<div class="post-metadata">

**Author:** ![haavardbj](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@haavardbj](https://discourse.nodered.org/u/haavardbj)\
**Post date:** [17 January 2022 20:12 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/7 "2022-01-17T20:12:39Z")

</div>

Maybe i was a bit unclear.. in my example i would like to only extra the value corresponding to: volt\_L1.  
If i use a change node to "extract" the value, the messeages that dosent have the value for volt\_L1 returnes as "undefined".

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

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [17 January 2022 20:15 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/8 "2022-01-17T20:15:13Z")

</div>

OK - then use the switch - I posted before and check for payload.volt\_L1 not null.

---

<div class="post-metadata">

**Author:** ![haavardbj](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@haavardbj](https://discourse.nodered.org/u/haavardbj)\
**Post date:** [17 January 2022 20:30 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/9 "2022-01-17T20:30:21Z")

</div>

Yes, sorry. This solves it.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae24c208e1018b192964d4f494dfb056fe696cbd.png)

---

<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:** [18 March 2022 20:30 UTC](https://discourse.nodered.org/t/how-to-only-pass-through-a-certain-part-of-an-array/56766/10 "2022-03-18T20:30:49Z")

</div>

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