How to delete a flow variable from a `function` node

I know........ Use the change node.

Please indulge me.

In one node I have:
flow.set('example',"something");

How do I delete the flow variable called example?

delete flow.example doesn't work.

Stuck.

1 Like

It’s not the most logical approach, but with some understanding of core JavaScript/core Node-RED logic it makes more sense: by setting it to undefined.

flow.set('example', undefined);

1 Like

Tried....

let x = flow.get('TRAIN');
if (x == 'HELD')
{
    msg.payload = "TRIP";
    msg.topic = "TRAIN";
    flow.set('TRAIN',undefind);
    return msg;
}
ReferenceError: undefind is not defined (line 6, col 22)

Doesn't work.

Maybe try spelling it as was shown ?

3 Likes

Thanks.

I worked around it and made it null rather than undefined

That’s not a work around. That defines it as null. So it still exists.

Oh.

Well, from the code I posted, it simply needs to not be HELD

But I may change it to undefined.
(I think the parser was stuffed up because I was doing it via audio and it messed up the fined/find part)

The error was that you had spelt it undefind instead of undefined. Hence the error message "undefind is not defined"
Of course undefined is not defined also, but in this case would not throw an error.

Colin, I agree and just admitted it.

The problem was the find part.
Rather than fined it was parsed as find.

Parsed by me.

Because sometimes a picture says more than a thousand words:

null is the assignment of the value “nothing” to a variable. undefined the declaration of a variable without a value.

18 Likes

Lovely!!!!

@dceejay

I know...xmas is over...but is there also New Year Gifts available?
Kind regards, Walter

Working with context in function nodes

We have an item on the backlog to add a delete function to the context API. It sits there alongside everything else that waits for someone to do.

2 Likes

Oh, I see, well with the very well illustrated explanation given about null & undefined, the work around is working great (used it myself) so there is no real urgency I think

Anyway, I would then like to take the opportunity, to thank everybody for a great NR year and wish all a Happy New (NR) Year to come

2 Likes

Is there a contribution guide I can follow? We're looking to use Node-RED for some of our ESB services and I'd like to pitch in where I can.

See https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md

It works fine. Thx!:facepunch: