# Splitting array - from MySQL query

**URL:** <https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279>\
**Category:** General\
**Created:** [8 March 2021 20:37 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279 "2021-03-08T20:37:19Z")\
**Posts on this page:** 17\
**Page:** 2

<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:** [9 March 2021 13:44 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/21 "2021-03-09T13:44:04Z")

</div>

Thanks all,

The two methods high lighted in yellow works.

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

---

<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:** [9 March 2021 13:47 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/22 "2021-03-09T13:47:02Z")

</div>

good stuff.

NOTE - the "hacky" version i posted is identical to the JSON --\> JSON version (in that the JSON nodes pretty much do `JSON.stringify` --\> `JSON.parse` under the hood)

I would recommend the first solution over stringify/parse (if it works)

could you also test....

```auto
var rows = msg.payload.map((result) => ({
    ...result,
}));

for (let i=0; i<rows.length; i++) {
    node.send({payload: rows[i]})
}
return null

```

---

<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:** [9 March 2021 15:08 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/23 "2021-03-09T15:08:55Z")

</div>

Yes this works , thank you Sir

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 March 2021 15:17 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/24 "2021-03-09T15:17:30Z")

</div>

Just to be clear, although the output of the `split` node (after the `mysql` node) looks like [Object object] when sent to a `debug` node displaying 'msg.payload', the data is in the msg and can be accessed, the `function` node is not needed. If you change the `debug` node to display the 'Complete msg object' you will see all the data.

---

<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:** [9 March 2021 15:20 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/25 "2021-03-09T15:20:04Z")

</div>

I am on v1.2.9, where do you select 'Complete msg object'?

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

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 March 2021 15:22 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/26 "2021-03-09T15:22:06Z")

</div>

![Screen Shot 2021-03-09 at 10.21.28 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/f/0f7c7522b3ca01e81a044df309778703f724c21f.png)

---

<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:** [9 March 2021 15:24 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/27 "2021-03-09T15:24:13Z")

</div>

Thank you

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [9 March 2021 15:37 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/28 "2021-03-09T15:37:14Z")

</div>

... though if the end result is to plot on the worldmap then the function could actually map the property names into new objects at the same time... but ok yeah one step at a time.

---

<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:** [9 March 2021 16:22 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/29 "2021-03-09T16:22:45Z")

</div>

That is is what the grand master architecture for the flow is at the end of the day,

So now map msg.payload.tl\_lat and msg.payload.tl\_lon to msg.payload.lat and msg.payload.lon

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [9 March 2021 18:42 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/30 "2021-03-09T18:42:16Z")

</div>

And sen\_id to name. (And maybe add icon and iconColor. )

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 March 2021 16:06 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/31 "2021-03-13T16:06:29Z")

</div>

@ScheepersJohan Johan, just to let you know. there is a new version of node-red-node-mysql (v0,1,2) where the `RowDataPacket objects` issue has been fixed so you won't see the `[Object object]` in a debug showing only msg.payload..

---

<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:** [15 March 2021 09:21 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/32 "2021-03-15T09:21:52Z")

</div>

Thank I will update.

---

<div class="post-metadata">

**Author:** ![berijan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/berijan/32/35313_2.png) [@berijan](https://discourse.nodered.org/u/berijan)\
**Post date:** [15 March 2021 11:51 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/33 "2021-03-15T11:51:06Z")

</div>

A Function node with this code

```auto
let outputMsgs = [];
let parts = msg.payload;
for (var part in parts) {
    outputMsgs.push({payload:parts[part]});
}
return [outputMsgs];  
//The [] arround the array 'outputMsgs' sends each item in the array as an own message.

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 March 2021 11:59 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/34 "2021-03-15T11:59:32Z")

</div>

@berijan a `split` node will also split the array into seperate messages.

---

<div class="post-metadata">

**Author:** ![berijan](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/berijan/32/35313_2.png) [@berijan](https://discourse.nodered.org/u/berijan)\
**Post date:** [15 March 2021 13:18 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/35 "2021-03-15T13:18:27Z")

</div>

Yes I know about the Split-node but when browsing through the tread understood it as TS tried the Split without success therefore I suggested to try the Function node.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [15 March 2021 13:33 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/36 "2021-03-15T13:33:01Z")

</div>

> [@berijan](#):
>
> when browsing through the tread understood it as TS tried the Split without success

Yes that was the original problem, but the fix in v0.1.2 of the `MySQL` node takes care of it.

---

<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:** [14 May 2021 13:33 UTC](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279/37 "2021-05-14T13:33:55Z")

</div>

Closed on 14 May 2021 13:33 UTC

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

[Previous page](https://discourse.nodered.org/t/splitting-array-from-mysql-query/42279.md?page=1)
