var type = "chance"; //or "chest" ;
var title = cards.type[0].title; //type is variable not an actual property of cards
而不是键入我想要使用变量的属性名称,因为它可以是cards.chance[0].title
或cards.chest[0].title
答案 0 :(得分:1)
尝试[]
语法:
var type = "chance"; //or "chest" ;
var title = cards[type][0].title;