# Loop through array of object

**URL:** https://discourse.nodered.org/t/loop-through-array-of-object/62278
**Category:** General
**Created:** [6 May 2022 09:02 UTC](https://discourse.nodered.org/t/loop-through-array-of-object/62278 "2022-05-06T09:02:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![NeetaJ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/neetaj/32/60934_2.png) [@NeetaJ](https://discourse.nodered.org/u/NeetaJ)
#### Post date: [6 May 2022 09:02 UTC](https://discourse.nodered.org/t/loop-through-array-of-object/62278/1 "2022-05-06T09:02:24Z")

</div>

Hi,

I have this flow

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/78960e09d40e313b5101be0b658b4e80ccf03c11.png)

and its corresponding output is

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

I need to access the highlighted values. Can anybody help with the function.

Thanks,  
Neeta

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [6 May 2022 09:28 UTC](https://discourse.nodered.org/t/loop-through-array-of-object/62278/2 "2022-05-06T09:28:55Z")

</div>

Hi Neeta,

If you hover your mouse over one of the highlighted entries, you will see some options appear one of which lets you copy the path to the object.

With that in hand, you can, if you need to walk through the array, replace any array references with a looping function.

```auto
msg.payload.sensordatavalues.forEach( (val) => {
    // val.value and val.value_type are what you need
})

```

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [6 May 2022 11:16 UTC](https://discourse.nodered.org/t/loop-through-array-of-object/62278/3 "2022-05-06T11:16:37Z")

</div>

You can also loop through the array using a split node.  
e.g.

```auto
[{"id":"354197ee.e1a278","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload.sensor_data_values","v":"[{\"value\":\"2:20\",\"data_type\":\"f1\",\"id\":1234},{\"value\":\"3:20\",\"data_type\":\"f2\",\"id\":1235}]","vt":"json"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":100,"y":80,"wires":[["fa34fe67.be89c","208ed9c4.f23cce"]]},{"id":"fa34fe67.be89c","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":430,"y":80,"wires":[]},{"id":"208ed9c4.f23cce","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"move","p":"payload.sensor_data_values","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":120,"wires":[["f49a9fd5.5aa04"]]},{"id":"f49a9fd5.5aa04","type":"split","z":"bf9e1e33.030598","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":630,"y":120,"wires":[["c800f9d1.d02bf8"]]},{"id":"c800f9d1.d02bf8","type":"debug","z":"bf9e1e33.030598","name":"do something to each array element","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":880,"y":120,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![NeetaJ](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/neetaj/32/60934_2.png) [@NeetaJ](https://discourse.nodered.org/u/NeetaJ)
#### Post date: [12 May 2022 12:33 UTC](https://discourse.nodered.org/t/loop-through-array-of-object/62278/4 "2022-05-12T12:33:48Z")

</div>

Thanks you so much. worked for me

---

<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: [26 May 2022 12:34 UTC](https://discourse.nodered.org/t/loop-through-array-of-object/62278/5 "2022-05-26T12:34:22Z")

</div>

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