Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Переменная в ассоциативном массиве. (https://javascript.ru/forum/misc/34461-peremennaya-v-associativnom-massive.html)

HaseProgram 05.01.2013 20:17

Переменная в ассоциативном массиве.
 
Всем привет! Есть следующий код:

function translate(text) {
	var translation_array = {
		error_template_not_found : "Error, tamplate no found.",
                success_download_comp : "Download comleated successfull"
	}
}


Мне надо вывести соответствующее значение из переменной text. Если переменная text=error_template_not_found, то выводит Error, tamplate no found. Через alert(translation_array.text); не получается, подскажите чайнику пожалуйста :D

Amphiluke 05.01.2013 20:32

alert(translation_array[text]);

HaseProgram 05.01.2013 20:36

Мда, спасибо :D


Часовой пояс GMT +3, время: 11:35.