How to get the value of a property using variable as name?

Asked

Viewed 67 times

5

How to make him search the property ABC instead of A? Taking this code into account:

A = 'ABC';    
alert(LANG.A);
  • As such, explain better. And what is LANG?

  • @bfavaretto a JSON tree

  • alert(LANG[A]); - That’s what you want?

1 answer

7


The LANG.A of your example looks for a property called A in the object LANG. Already LANG[A] finds a property whose name is the variable value A, that is to say, 'ABC' - is therefore equivalent to LANG.ABC. I believe you’re looking for this second case.

  • Wow I completely forgot the clasps, thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.