In the typescript, I have the following:
information_1: any;
information_2: any;
information_3: any;
for(var datum in data){
this.information_[datum] = data[datum]; //Of course this is not right.
}
In js, there is a way to dynamically assign a part of variable name. Is there something like that in typescript so that I can have this.information_1
or this.information_2
etc. based on the var datum
?
Thanks.
You certainly can, but you'll need to avoid the dot notation.
[key:string]:any;
for(var datum in data){
this['information_' + datum] = data[datum];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With