Flow.set using variable

I thought this was asked before but can't find it. Is there a way , and if so how to write to flow using a variable name such as
flow.set(MyVariable,1).
I've got a workaround so now I'm in education mode.
Thanks

Hi @gerry ..

flow.set(<KEY>,<value>)

So... <KEY> (providing its a string) - can come from anywhere (mostly)

Think of <KEY> as anything that evaluates to a string (the Name of the variable)

flow.set(msg.payload.keyName,1) /* Variable Name in `msg` */
flow.set(flow.get('varName'),1) /* Variable Name from another variable */
flow.set('varName',1) /* static name */

So that's my problem, mine was a number sequence 1 then 2 then 3 , convert to a string should work, thanks for the pointer

Just to be clear.

flow.set(< KEY>,< value>)
Where < KEY> is entered with quotes or single quote
Example flow.set(‘mykey’ , 1)

You do not need to convert integers to strings. You can use any data type. The KEY name is expressed this way as a literal. You can also use a variable which its value would hold the KEY name.

var Newkey = “mykey”;
flow.set(Newkey,1);