# Context arrays/objects - stuck

**URL:** https://discourse.nodered.org/t/context-arrays-objects-stuck/76722
**Category:** General
**Created:** [20 March 2023 03:43 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722 "2023-03-20T03:43:19Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 03:43 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/1 "2023-03-20T03:43:19Z")

</div>

I've done a bit of searching when starting the post and looked at a couple of suggestions.  
Sorry. I can't see them as answers.

Code:

```auto
let value = msg.payload;
let red = flow.get("red");
let led = flow.get("led") || 0;
red[led] = value;
flow.set("red",red[]);

```

`msg.payload` if the value I want to store.  
`flow "red"` is the array (object?) to which I want to save.

I probably have this back to front how I am doing it.  
But I don't see anything _wrong_ with this way, other than it can be done other ways.

8 LEDs.  
A slider selected which LED.

Another 3 sliders that set the RGB value.

I slide the LED selector to which LED.  
I then slide the RGB sliders to set the value.  
_I move to another LED and .... what ever._

I come back to _this_ LED and it gets the stored values.

But I'm stuck how to store them in flow context.

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [20 March 2023 06:38 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/2 "2023-03-20T06:38:17Z")

</div>

```auto
let value = msg.payload;
let red = flow.get("red") || []; // to be sure...
let led = flow.get("led") || 0;
red[led] = value;
flow.set("red",red); // <--- it's just 'red' here...

```

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 07:45 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/3 "2023-03-20T07:45:10Z")

</div>

Ok, so I've expanded the code you posted and got this.

It is working.

```auto
const colour = "green";

let value = msg.payload;
let colourarray = flow.get(colour) || []; // to be sure...
node.warn(colour + " " + colourarray);
let led = flow.get("led") || 0;
node.warn("LED " + led);
colourarray[led] = value;
node.warn("Value " + value);
flow.set(colour, colourarray); // <--- it's just 'red' here...

return msg;

```

Then I repeat it for RED, GREEN and BLUE by just changing the name in the first line.

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [20 March 2023 08:14 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/4 "2023-03-20T08:14:51Z")

</div>

> [@Trying\_to\_learn](#):
>
> Then I repeat it for RED, GREEN and BLUE by just changing the name in the first line.

Perhaps it would be possible even to pass `color` & `led` via msg ... like `msg.color` and `msg.led`? That could save you the detour via the (flow) context storage...

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 08:20 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/5 "2023-03-20T08:20:51Z")

</div>

Yeah, I am having a dog's breakfast time getting the messages to work.

I don't know a _trick_ to save/get the values as I have it.

This is my effort at doing it.

The `joining` is not working - yet.

```auto
[{"id":"17dbb7a79d452473","type":"ui_slider","z":"aad05e94.e66068","name":"Led #","label":"LED #","tooltip":"","group":"63062421.073624","order":8,"width":"1","height":"4","passthru":true,"outs":"end","topic":"","topicType":"str","min":"0","max":"8","step":1,"className":"","x":370,"y":420,"wires":[["88c920636f44c4a2","87bb22d45d50f084","f631cfdc783f4675","37220ad3c699cef9"]]},{"id":"88c920636f44c4a2","type":"change","z":"aad05e94.e66068","name":"LED","rules":[{"t":"set","p":"led","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":420,"wires":[[]]},{"id":"87bb22d45d50f084","type":"function","z":"aad05e94.e66068","name":"Get value","func":"let led = msg.payload;\nlet colour = flow.get(\"blue\");\nlet value = colour[led] || 0;\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":340,"wires":[["24bd77c7.2dddc"]]},{"id":"f631cfdc783f4675","type":"function","z":"aad05e94.e66068","name":"Get value","func":"let led = msg.payload;\nlet colour = flow.get(\"green\");\nlet value = colour[led] || 0;\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":250,"wires":[["8f3b1f2f.9e01c"]]},{"id":"37220ad3c699cef9","type":"function","z":"aad05e94.e66068","name":"Get value","func":"let led = msg.payload;\nlet colour = flow.get(\"red\");\nlet value = colour[led] || 0;\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":160,"y":160,"wires":[["ecf6cee4.39079","afbcc2d62aa85d4b"]]},{"id":"ecf6cee4.39079","type":"ui_slider","z":"aad05e94.e66068","name":"Red","label":"Red","tooltip":"","group":"63062421.073624","order":2,"width":"1","height":"6","passthru":true,"outs":"end","topic":"","topicType":"str","min":"1","max":"255","step":1,"className":"","x":370,"y":160,"wires":[["0fc7261e9ef75ad6","b6e196cfdabe0b9f","39c06764.4def"]]},{"id":"8f3b1f2f.9e01c","type":"ui_slider","z":"aad05e94.e66068","name":"Green","label":"Green","tooltip":"","group":"63062421.073624","order":3,"width":"1","height":"6","passthru":true,"outs":"end","topic":"","min":0,"max":"255","step":1,"x":370,"y":250,"wires":[["f1af2a73.5f669","f897fd3f34685f74"]]},{"id":"24bd77c7.2dddc","type":"ui_slider","z":"aad05e94.e66068","name":"Blue","label":"Blue","tooltip":"","group":"63062421.073624","order":4,"width":"1","height":"6","passthru":true,"outs":"end","topic":"","topicType":"str","min":"1","max":"255","step":1,"className":"","x":370,"y":340,"wires":[["ce0753a5.23b75","b2092751f72b5254"]]},{"id":"b2092751f72b5254","type":"function","z":"aad05e94.e66068","name":"function 23","func":"const colour = \"blue\";\n\n\nlet value = msg.payload;\nlet colourarray = flow.get(colour) || []; // to be sure...\n//node.warn(colour + \" \" + colourarray);\nlet led = flow.get(\"led\") || 0;\n//node.warn(\"LED \" + led);\ncolourarray[led] = value;\n//node.warn(\"Value \" + value);\nflow.set(colour, colourarray); // <--- it's just 'red' here...\n\nmsg.blue = value;\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":340,"wires":[["7d60d18efd5768f4","604d314712cea41f"]]},{"id":"f897fd3f34685f74","type":"function","z":"aad05e94.e66068","name":"function 22","func":"const colour = \"green\";\n\n\nlet value = msg.payload;\nlet colourarray = flow.get(colour) || []; // to be sure...\n//node.warn(colour + \" \" + colourarray);\nlet led = flow.get(\"led\") || 0;\n//node.warn(\"LED \" + led);\ncolourarray[led] = value;\n//node.warn(\"Value \" + value);\nflow.set(colour, colourarray); // <--- it's just 'red' here...\n\nmsg.green = value;\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":250,"wires":[["7d60d18efd5768f4","02072a97ee82277e"]]},{"id":"b6e196cfdabe0b9f","type":"function","z":"aad05e94.e66068","name":"function 21","func":"const colour = \"red\";\n\n\nlet value = msg.payload;\nlet colourarray = flow.get(colour) || []; // to be sure...\n//node.warn(colour + \" \" + colourarray);\nlet led = flow.get(\"led\") || 0;\n//node.warn(\"LED \" + led);\ncolourarray[led] = value;\n//node.warn(\"Value \" + value);\nflow.set(colour, colourarray); // <--- it's just 'red' here...\n\nmsg.red = value;\nmsg.payload = \"\";\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":160,"wires":[["51c7bfa856021aca","7d60d18efd5768f4"]]},{"id":"63062421.073624","type":"ui_group","name":"LED colour adjustments","tab":"e92ac76d.c24e7","order":10,"disp":true,"width":"7","collapse":false},{"id":"e92ac76d.c24e7","type":"ui_tab","name":"Real_World_Control","icon":"dashboard","order":5,"disabled":false,"hidden":false}]

```

Sorry.

There are 4 sliders.

(I don't know why I punish myself like this.)

Oh, ok, just before I post:  
The 3 `function` nodes.  
(I'm trying to do the _right_ thing with variable names.)  
But I seem to be missing something.

```auto
const colour = "blue"; // This sets which colour is being done.

let value = msg.payload;
let colourarray = flow.get(colour) || []; // to be sure...
//node.warn(colour + " " + colourarray);
let led = flow.get("led") || 0;
//node.warn("LED " + led);
colourarray[led] = value;
//node.warn("Value " + value);
flow.set(colour, colourarray); // <--- it's just 'red' here...

// How do I use colour here though? Rather than saying BLUE how can I use the
// variable name? That way I only change the one line for all 3 colours.
msg.blue = value;
msg.payload = "";
return msg;

```

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [20 March 2023 08:27 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/6 "2023-03-20T08:27:01Z")

</div>

> [@Trying\_to\_learn](#):
>
> `How do I use colour here though?`

Change

> [@Trying\_to\_learn](#):
>
> `msg.blue = value;`

to

```auto
msg[color] = value;

```

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 08:30 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/7 "2023-03-20T08:30:56Z")

</div>

# {{THANKS}}

I am really redefining my stupidity today.

I think I'm going for a new record. 😉

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 09:10 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/8 "2023-03-20T09:10:29Z")

</div>

(Really pushing the friendship.)

Now I'm stuck with how to `join` the three messages.  
Other than a `join` node that's about the best way to create the message with the structure:  
`rgb,led,red.green,blue` from the flow contexts stored.

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [20 March 2023 09:37 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/9 "2023-03-20T09:37:48Z")

</div>

If the different values arrive one by one (like in the flow you posted above), there's little more option than to go via a (flow) context store ... & join the data.

Where's this data coming from in reality?  
How's you flow looking so far?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 09:41 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/10 "2023-03-20T09:41:12Z")

</div>

The flow (the other one) is looking good.

This one:  
The data does come from the sliders set.  
(Well.... Kind of.)  
The sliders set the flow context. Then the message goes down to a `join` node.  
That gets the 3 messages (RGB) and joins them together to make the message to send to the LED.

I just don't understand the terms to describe the types of messages to create from the join.

I'm making slow progress though. but am open to help with what type of message I want to create coming out of the `join` node.  
It really needs to be text.

## Update:

Ok. I NEARLY have it working now.

☹

No. Sorry, I am missing something.

Here's what I have.

Excuse the mess. It is very much Work In Progress.

```auto
[{"id":"35372c65.4d2b44","type":"inject","z":"aad05e94.e66068","name":"R","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":850,"y":40,"wires":[["b6e196cfdabe0b9f"]]},{"id":"0e626f214207980d","type":"inject","z":"aad05e94.e66068","name":"G","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2","payloadType":"num","x":850,"y":80,"wires":[["f897fd3f34685f74"]]},{"id":"a6471d5af6829c96","type":"inject","z":"aad05e94.e66068","name":"B","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"3","payloadType":"num","x":850,"y":120,"wires":[["b2092751f72b5254"]]},{"id":"b6e196cfdabe0b9f","type":"function","z":"aad05e94.e66068","name":"function 21","func":"const colour = \"red\";\n\n\nlet value = msg.payload;\nlet colourarray = flow.get(colour) || []; // to be sure...\n//node.warn(colour + \" \" + colourarray);\nlet led = flow.get(\"led\") || 0;\n//node.warn(\"LED \" + led);\ncolourarray[led] = value;\n//node.warn(\"Value \" + value);\nflow.set(colour, colourarray); // <--- it's just 'red' here...\n\nmsg[colour] = value;\nmsg.led = led;\nmsg.payload = \"\";\nmsg.count = 1;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":160,"wires":[["7d60d18efd5768f4"]]},{"id":"f897fd3f34685f74","type":"function","z":"aad05e94.e66068","name":"function 22","func":"const colour = \"green\";\n\n\nlet value = msg.payload;\nlet colourarray = flow.get(colour) || []; // to be sure...\n//node.warn(colour + \" \" + colourarray);\nlet led = flow.get(\"led\") || 0;\n//node.warn(\"LED \" + led);\ncolourarray[led] = value;\n//node.warn(\"Value \" + value);\nflow.set(colour, colourarray); // <--- it's just 'red' here...\n\nmsg[colour] = value;\nmsg.led = led;\nmsg.payload = \"\";\nmsg.count = 2;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":250,"wires":[["7d60d18efd5768f4"]]},{"id":"b2092751f72b5254","type":"function","z":"aad05e94.e66068","name":"function 23","func":"const colour = \"blue\";\n\n\nlet value = msg.payload;\nlet colourarray = flow.get(colour) || []; // to be sure...\n//node.warn(colour + \" \" + colourarray);\nlet led = flow.get(\"led\") || 0;\n//node.warn(\"LED \" + led);\ncolourarray[led] = value;\n//node.warn(\"Value \" + value);\nflow.set(colour, colourarray); // <--- it's just 'red' here...\n\nmsg[colour] = value;\nmsg.led = led;\nmsg.payload = \"\";\nmsg.count = 3;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":340,"wires":[["7d60d18efd5768f4"]]},{"id":"80710d1c90418e74","type":"function","z":"aad05e94.e66068","name":"check led is set.","func":"let led = flow.get(\"led\");\nif (led == undefined)\n{\n led = 0;\n}\nmsg.payload = led;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":815,"y":250,"wires":[["5bcad49e022276f6","70ad4dc8f6934651","b1261f7c8bbfd9ec","ed98e13865cb8bd3"]],"l":false},{"id":"7d60d18efd5768f4","type":"junction","z":"aad05e94.e66068","x":740,"y":250,"wires":[["80710d1c90418e74"]]},{"id":"5bcad49e022276f6","type":"join","z":"aad05e94.e66068","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":",","joinerType":"str","accumulate":false,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":960,"y":250,"wires":[["b8fa5a143c8d46e0"]]},{"id":"b8fa5a143c8d46e0","type":"function","z":"aad05e94.e66068","name":"Get LED","func":"msg.led = flow.get(\"led\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1045,"y":250,"wires":[["10cea6927ad0f342"]],"l":false},{"id":"10cea6927ad0f342","type":"template","z":"aad05e94.e66068","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"rgb,{{led}},{{payload}}","output":"str","x":1180,"y":250,"wires":[["b3889d2734bf3fd4","5519e5f0.fe798c"]]},{"id":"5519e5f0.fe798c","type":"debug","z":"aad05e94.e66068","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":200,"wires":[]},{"id":"70ad4dc8f6934651","type":"switch","z":"aad05e94.e66068","name":"","property":"red","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":1055,"y":70,"wires":[["51c7bfa856021aca"]],"l":false},{"id":"51c7bfa856021aca","type":"debug","z":"aad05e94.e66068","name":"RED sent","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":70,"wires":[]},{"id":"b1261f7c8bbfd9ec","type":"switch","z":"aad05e94.e66068","name":"","property":"green","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":1055,"y":110,"wires":[["02072a97ee82277e"]],"l":false},{"id":"02072a97ee82277e","type":"debug","z":"aad05e94.e66068","name":"GREEN sent","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1160,"y":110,"wires":[]},{"id":"ed98e13865cb8bd3","type":"switch","z":"aad05e94.e66068","name":"","property":"blue","propertyType":"msg","rules":[{"t":"nnull"}],"checkall":"true","repair":false,"outputs":1,"x":1055,"y":150,"wires":[["604d314712cea41f"]],"l":false},{"id":"604d314712cea41f","type":"debug","z":"aad05e94.e66068","name":"BLUE sent","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1160,"y":150,"wires":[]}]

```

The unnamed `debug` is the important one.

But it is not getting the stored values.  
It is getting the LED value for the RGB values.

Stuck how I _fix_ this.

Oh, you may need to set flow context.

Piccie may help

 ![Screenshot from 2023-03-20 20-49-09](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/8/785e5039888558cadc05cb28f8ac178de6f71c44.png)

---

<div class="post-metadata">

### Author: ![ralphwetzel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ralphwetzel/32/53713_2.png) [@ralphwetzel](https://discourse.nodered.org/u/ralphwetzel)
#### Post date: [20 March 2023 10:13 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/11 "2023-03-20T10:13:02Z")

</div>

Once you utilize a function node, there should be no need to make it that complicated:

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

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

```auto
[
    {
        "id": "1102b9a47de6f467",
        "type": "tab",
        "label": "Flow 25",
        "disabled": false,
        "info": "",
        "env": [],
        "_mcu": {
            "mcu": false
        }
    },
    {
        "id": "35372c65.4d2b44",
        "type": "inject",
        "z": "1102b9a47de6f467",
        "name": "R",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "1",
        "payloadType": "num",
        "_mcu": {
            "mcu": false
        },
        "x": 110,
        "y": 180,
        "wires": [
            [
                "c82221dd5aa252d3"
            ]
        ]
    },
    {
        "id": "0e626f214207980d",
        "type": "inject",
        "z": "1102b9a47de6f467",
        "name": "G",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "2",
        "payloadType": "num",
        "_mcu": {
            "mcu": false
        },
        "x": 110,
        "y": 240,
        "wires": [
            [
                "87aa021b210538b4"
            ]
        ]
    },
    {
        "id": "a6471d5af6829c96",
        "type": "inject",
        "z": "1102b9a47de6f467",
        "name": "B",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "_mcu": {
            "mcu": false
        },
        "x": 110,
        "y": 300,
        "wires": [
            [
                "31cf07bd46e0efdd"
            ]
        ]
    },
    {
        "id": "80710d1c90418e74",
        "type": "function",
        "z": "1102b9a47de6f467",
        "name": "make join",
        "func": "const led = flow.get(\"led\") || 0;\nconst red = flow.get(\"red\") || 0;\nconst green = flow.get(\"green\") || 0;\nconst blue = flow.get(\"blue\") || 0;\n\nlet p = `rgb, ${led}, ${red}, ${green}, ${blue}`;\n\nmsg.payload = p;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "_mcu": {
            "mcu": false
        },
        "x": 520,
        "y": 240,
        "wires": [
            [
                "5519e5f0.fe798c"
            ]
        ]
    },
    {
        "id": "5519e5f0.fe798c",
        "type": "debug",
        "z": "1102b9a47de6f467",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "_mcu": {
            "mcu": false
        },
        "x": 710,
        "y": 240,
        "wires": []
    },
    {
        "id": "c82221dd5aa252d3",
        "type": "change",
        "z": "1102b9a47de6f467",
        "name": "red",
        "rules": [
            {
                "t": "set",
                "p": "red",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "_mcu": {
            "mcu": false
        },
        "x": 310,
        "y": 180,
        "wires": [
            [
                "80710d1c90418e74"
            ]
        ]
    },
    {
        "id": "87aa021b210538b4",
        "type": "change",
        "z": "1102b9a47de6f467",
        "name": "green",
        "rules": [
            {
                "t": "set",
                "p": "green",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "_mcu": {
            "mcu": false
        },
        "x": 290,
        "y": 240,
        "wires": [
            [
                "80710d1c90418e74"
            ]
        ]
    },
    {
        "id": "31cf07bd46e0efdd",
        "type": "change",
        "z": "1102b9a47de6f467",
        "name": "blue",
        "rules": [
            {
                "t": "set",
                "p": "blue",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "_mcu": {
            "mcu": false
        },
        "x": 310,
        "y": 300,
        "wires": [
            [
                "80710d1c90418e74"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 10:19 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/12 "2023-03-20T10:19:17Z")

</div>

(Sorry, I was eating.)

Ok.

So..... but the red, green and blue are arrays in context. But that is a different level of the things working.

I'm not seeing how it works just now.

I'll import it and see if I can make more sense of it.

I fear something was lost in translation.

 ![Screenshot from 2023-03-20 21-26-14](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02e0ca7a8d8d6ba8254da750e0c7e4507baae121.png)

Each time I pressed the `inject` node/s I get these weird outputs.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 10:36 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/13 "2023-03-20T10:36:32Z")

</div>

Concentrating on the `function` node:

```auto
let led = flow.get("led");
if (led == undefined)
{
    led = 8;
}

//==
let red = flow.get("red");
let redvalue = red[led] || 0;

let green = flow.get("green");
let greenvalue = green[led] || 0;

let blue = flow.get("blue");
let bluevalue = blue[led] || 0;
//==

//const redx = flow.get("red") || 0;
//const greenx = flow.get("green") || 0;
//const bluex = flow.get("blue") || 0;

let p = `rgb, ${led}, ${redvalue}, ${greenvalue}, ${bluevalue}`;

msg.payload = p;
return msg;

```

Better?

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [20 March 2023 11:14 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/14 "2023-03-20T11:14:56Z")

</div>

Worked it out.

Got it working and did a bit of other _tweaking_.  
Found a few problems too and fixed them. 🙂  
Thanks again for the help and time.

---

<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: [3 April 2023 11:15 UTC](https://discourse.nodered.org/t/context-arrays-objects-stuck/76722/15 "2023-04-03T11:15:08Z")

</div>

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