I am facing an issue with selecting pre-defined variables within a component. Here are the variables in question:
public editable1: number = 0;
public editable2: number = 0;
public editable3: number = 0;
public editable4: number = 0;
public editable5: number = 0;
Next, I have an array of arrays:
public editors: []=[
['editable1', 'editable3', 'editable5'],
['editable1', 'editable2', 'editable3']
]
My goal is to increment these variables based on the lists provided in the array.
this.editors.forEach(element => {
element.forEach(e => {
this['e']++; // My intention here is to reference the predefined variables, but it's not working as expected
});
});
How can I resolve this issue?
Edit: The suggested solution works perfectly fine, but I would like to provide additional information regarding syntax for more complex code. I have changed the variable that needs to be edited, and now it is nested inside service.object.object.key:value structure. Therefore, the code looks like this:
this.editors.forEach(element => {
element.forEach(e => {
(this.service.object as any)[e].key++; // This allows me to increment the value of an object within an object, which is located in a service
});
});