Search code examples
javascriptnode.jsnode-red

Query result to variable(Node red)


I have a problem, I want to move value of Object[0] nazwa, which is a result of query (let's say "ab" in this case) to another variable, however I'm new to red node and JS, so I don't know how to do it. Could anyone be so kind and would help me? Right now I have it in function like so:

global.set("zmienna",msg.payload.Object[0].nazwa)

but it does not work.

enter image description here


Solution

  • global.set("zmienna", msg.payload2[0].nazwa);
    

    Explained:

    • I see from your debug console that payload2 is an array, while payload is a string, so you are probably referring to that variable.
    • The object you see on the right side of your variable in console is the type of the variable, not it's name, so you shouldn't use it to access your values.