0

I want to pass the item variable dynamic into this property e.g. If the item has value of 35 it will become this.BookingConfirmationFormsState35

onChange( event, item ){
   console.log( this.BookingConfirmationFormsState+item ); // Doesn't work
}
Devil Raily
  • 552
  • 1
  • 5
  • 15

2 Answers2

1
onChange( event, item ){
   console.log( this['BookingConfirmationFormsState' + item]);
}
Villa7_
  • 2,337
  • 2
  • 19
  • 23
1

You need to use bracket notation [] to access the dynamic property name:

this['BookingConfirmationFormsState' + item];

For item = 35, the above code is equivalent to:

this.BookingConfirmationFormsState35
hackerrdave
  • 5,946
  • 1
  • 23
  • 28