Подтвердить что ты не робот

Как получить доступ к объекту с помощью переменной

У меня есть объект

var Messages = {
'fullName' : 'Tell us your cool name dude..! e.g. Yousuf Iqbal',
'userName' : 'Choose a catchy username. Remember! It should be available :)',
'password' : 'Choose a top secret password with special chars, numbers and alphabets',
'rePassword' : 'Retype the password you just typed. But, don\'t try to copy!',
'bYear' : 'Tell the year, in which this bomb blasted'
};

и переменной..

var attribute = $('#userinfo form input').attr('name');

теперь я хочу выбрать свойство объектов Messages, используя эту переменную, как это.

var message = Messages.attribute;

но не работает. и также попробовали следующее.

var message = Messages+'.'+attribute;
4b9b3361

Ответ 1

Квадратные скобки:

message = Messages[ attribute ];

Ответ 2

var message = Messages[attribute];