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
  • 385
  • 2
  • 6
  • 20

1 Answers1

2

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

toolState[dynamicText] = true;
Sterling Archer
  • 22,070
  • 18
  • 81
  • 118