1

I am attempting to dynamically access an object with a property value that is contained within a string. Example below:

var toolState = {
    draw_point: false;
    draw_line: false;
}

var dynamicText = "draw_point";

toolState.dynamicText = true; //here is the problem

I'm fairly new to JS. Sorry if this is a silly question.

Thanks

thebighoncho
  • 365
  • 2
  • 4
  • 18

1 Answers1

2

Use bracket notation instead of dot notation for variable names as properties.

toolState[dynamicText] = true;
Sterling Archer
  • 21,348
  • 17
  • 79
  • 113