How to create dynamic ReactiveVar

Hi,

var x = “something”;
Session.set(x, “anything”).

can you do the same with ReactiveVar?

this.x = new ReactiveVar(“anything”);

where x = “something”.

TIA!

You’ll want to take care that this is actually what you expect it to be, but you can assign object properties values using bracket notation to achieve your desired outcome.

var x = “something”;

this[x] = new ReactiveVar(“anything”);

Basically the ReactiveVar works just as the Session apart from that it is connected to a context, so it is always dynamic.

‘var’, ‘this’ and ‘Session’ is in your example just different context