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
  • 562
  • 1
  • 5
  • 15

2 Answers2

1
onChange( event, item ){
   console.log( this['BookingConfirmationFormsState' + item]);
}
tklg
  • 2,572
  • 2
  • 19
  • 24
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
  • 6,486
  • 1
  • 25
  • 29