I have a variable called demoVars
, which is an array of objects with properties var1, var2, and var3.
In my component class, I have a variable named selectedVar
that holds the name of one of these properties: var1, var2, or var3.
I want to dynamically push the value of the selected property from each object in demoVars
into another array called demoArr
.
To achieve this, depending on the value of selectedVar
, I need to push the corresponding property value for each object in demoVars
into demoArr
.
The issue arises when trying to use string interpolation within the push()
method to access the value of the selected property. The syntax used results in pushing the string literal instead of the actual value.
I am looking for the correct syntax or approach to accomplish this task effectively.