# Help - Need some advice

**URL:** https://discourse.nodered.org/t/help-need-some-advice/70254
**Category:** General
**Created:** [8 November 2022 12:16 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254 "2022-11-08T12:16:31Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)
#### Post date: [8 November 2022 12:16 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254/1 "2022-11-08T12:16:31Z")

</div>

I'm using Node Red & Raspberry Pi, to excute an Api call once daily. The Api retrieves the data from Gas wells that we have across the US. This amounts to 111 wells the data is returned back in Array like this. **(Please Note: I'm new to Node Red)**

object[0]  
meterid=123456  
DP=13.6  
AP=17.56  
Gas (mCF)=138.96

object[1]  
meterid=456789  
DP=14.6  
AP=19.56  
Gas (mCF)=183.96

object[2]  
meterid=963258  
DP=23.6  
AP=27.56  
Gas (mCF)=238.96

And so on all the way to object[111]

Now I going to publish this to our Mqtt broker using Sparkplug b. I know how to make this work for a single object, but I can't figure out how to move through each object . I could hard code everything but I'm sure there is a better way.

Would like any advice?

---

<div class="post-metadata">

### Author: ![ScheepersJohan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/scheepersjohan/32/39556_2.png) [@ScheepersJohan](https://discourse.nodered.org/u/ScheepersJohan)
#### Post date: [8 November 2022 12:25 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254/2 "2022-11-08T12:25:08Z")

</div>

You can use the split node and then deal with each msg. separately

---

<div class="post-metadata">

### Author: ![madhouse](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@madhouse](https://discourse.nodered.org/u/madhouse)
#### Post date: [8 November 2022 15:17 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254/3 "2022-11-08T15:17:56Z")

</div>

if you use a function node:

```auto
for(let x in msg.payload){
    //Perform some operations on the data for msg.payload[x].
}

```

Another variation that makes coding a little easier:

```auto
for(let x of msg.payload){
    //Perform some operations on the data for x.
}

```

The first variation uses x as an index to the position in the original variable. So you would reference it as something like `msg.payload[x].DP` to get the value for DP. The second variation actually makes x a copy of `msg.payload[x]` so that you can use x by itself like `x.DP`. If you know what you want to do with the components, just put that in the for loop and reference your variables like I showed you.

If you want to use a function, that is...

---

<div class="post-metadata">

### Author: ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)
#### Post date: [8 November 2022 17:00 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254/4 "2022-11-08T17:00:10Z")

</div>

I could split things out and thanks for the input.

I do want to look at what @madhouse suggest , It's just that since I'm trying to learn Javascript I was hoping for an easy way. But maybe I need to just dive in with both feet.

Thanks

---

<div class="post-metadata">

### Author: ![madhouse](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@madhouse](https://discourse.nodered.org/u/madhouse)
#### Post date: [8 November 2022 17:16 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254/5 "2022-11-08T17:16:25Z")

</div>

> [@damica51](#):
>
> I'm trying to learn Javascript I was hoping for an easy way. But maybe I need to just dive in with both feet.

That's a fair statement for anyone to make. Javascript is a very easy language and it's well documented all over the place. It's also a beast to learn and work with because it has so much it can do. And then there's all the variants like Node.js and Angular that carry most of the functionality, but not all. The good news is you don't have to bite off huge chunks and try to figure them out as you go. Node-Red makes it so you can put the hard parts together in nodes and then slowly either replace standard nodes with custom code or add specific functionality you can't find a node for.

If you want, I can walk you through any coding you may want to try. I'm no expert by any means. But a lot of my flows rely on functions instead of nodes because I find adding a couple lines of code into a function is a lot easier than adding several nodes. Just let me know.

---

<div class="post-metadata">

### Author: ![damica51](https://avatars.discourse-cdn.com/v4/letter/d/eb8c5e/32.png) [@damica51](https://discourse.nodered.org/u/damica51)
#### Post date: [8 November 2022 17:43 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254/6 "2022-11-08T17:43:32Z")

</div>

Thank you so much, I'm sure I will be asking for your help.

---

<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: [7 January 2023 17:43 UTC](https://discourse.nodered.org/t/help-need-some-advice/70254/7 "2023-01-07T17:43:39Z")

</div>

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