我試圖使用星號作爲對象的鍵引用時出現錯誤。我試着格式化不同的方式,但總是得到同樣的錯誤:在問題在對象中使用星號*作爲鍵
這裏是我的代碼與來自維基百科的API渲染的對象...
該生產線是:
console.log(shortcut.langlinks [index]。*);
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.");
}
}
如何格式化我的代碼以使星號顯示爲鍵值? 謝謝。
這些不是尖括號,這些是方括號:) –