Is there a way to read content variables from a script programatically?

Is there a way to read the value of a content variable by programmatically creating the name of the content variable?

For example:

var state = context.entities.NameOfState;
var taxRateVar = “content.” + state + “.taxrate”;
var taxRate = BotContent.get(taxRateVar);

Here is the use case:

I have a list of 50 content variables with names of states:

  1. content.alabama .taxrate = 7
  2. content.alaska.taxrate = 6
  3. content.wyoming.taxrate = 4

I have a single dialog task that reads the state through an entity variable. Instead of creating a switch case statement with 50 choices, or an if … else if structure with 50 branches, I would like to read the appropriate content variable using BotContent.get(taxRateVar) which would be similar to reading variables from
BotContext, UserSession or UserContext
UserContext.get(“firstName”);

This works!

var state = context.entities.NameOfState;
var taxRateVar = “content.” + state + “.taxrate”;
var taxRate = content[taxRateVar];

@harshal.mulherkar1
Thanks for sharing the solution. I was working on this too but I was thinking on different lines.
I will try to take your approach to the product team.

@santhosh.myadam