使用星号*作为对象中的键

Lek*_*eke 1 javascript

我试图使用星号作为对象的关键引用时出错.我尝试过格式化不同的方法,但总是得到同样的错误:

SyntaxError: missing name after . operator
Run Code Online (Sandbox Code Playgroud)

这是我的代码,其中包含从维基百科api呈现的对象...

有问题的一行是:

的console.log(shortcut.langlinks [索引]*);

var wp = {
    "query":{
        "pages":{
            "3823":{
                "pageid":3823,
                "ns":0,
                "title":"Binary",
                "extract":"<p><b>Binary</b> means <i>composed of two pieces or two parts</i> and may refer to:</p>\n\n",
                "links":[{
                    "ns":0,"title":"Binary-coded decimal"},{
                    "ns":0,"title":"Binary (Assemblage 23 song)"},{
                    "ns":0,"title":"Binary code"}],
                "langlinks":[{
                    "lang":"de","*":"Bin\u00e4r"},{
                    "lang":"fr","*":"Binaire"},{
                    "lang":"ur","*":"\u062a\u062b\u0646\u06cc\u06c1"}]
            }
        }
    }
};

var page_key = Object.keys( wp['query']['pages'])[0]; 
var shortcut = wp['query']['pages'][page_key];

function translation() {
    if (shortcut.langlinks.length > 0){
        for (var index in shortcut.langlinks){
            if (shortcut.langlinks[index].lang == 'de'){
                console.log(shortcut.langlinks[index].*);
            }
        }   
    } else {
        console.log("There are no language links.");
    }
}
Run Code Online (Sandbox Code Playgroud)

如何格式化代码以使星号显示为键值?谢谢.

Der*_*ony 5

您也可以使用括号:

shortcut.langlinks[index]['*']
Run Code Online (Sandbox Code Playgroud)