function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jugbeer BholaJugbeer Bhola 

Dynamic @Track variabes

Hello, I was wondering if there was a solution to this?  


If I had variables in aura I could set the value like this........

component.set("v.level" + number + "Disabled", true);

How can I do the same think in a Lightning Web Component?  The values are @track (ed).....

@track level1Disabled;
@track level2Disabled;
@track level3Disabled;
@track level4Disabled;

this.level1Disabled = true;

I want to do something like........

this."level" + number + "Disabled" = true
Best Answer chosen by Jugbeer Bhola
In JavaScript, you use the "index" notation, just like for an array, except it's a string that you use. We can also use the template literal to make it look a bit easier to read. You can do this:
this[`level${number}Disabled`] = true;