This question already has answers here:
Dynamically access object property using variable
                            
                                (14个回答)
                            
                    
                5年前关闭。
        

    

我正在尝试访问变量localise.courseEN,但它返回了undefinedEN

我该如何运作

var localise = {
    courseEN : "English",
}
var learnLang = "EN";
alert( localise.course + learnLang);

最佳答案

var localiseEN = {

    courseEN : "English"
};
var learnLang = 'EN';
alert( localiseEN.courseEN + learnLang);


像这样?

10-01 09:57