var el = { first : { earth : '100', fire : '200', water : '300' }, second : { earth : '400', fire : '500', water : '600' } } console.log(el.first.fire); //200 

How to implement the following code correctly?

 var meow = 'water'; console.log(el.first(meow)); //как вставить переменную meow, чтобы получилось 300? 

    1 answer 1

    Quote from the resource: https://learn.javascript.ru/object# access-through-square- box

    There is an alternative syntax for working with properties, using the brackets object ['property']:

    As a result, your code will be like this:

     var meow = 'water'; console.log(el.first[meow]); 

    Following the link - you can find a little more details.