好的,这可能听起来很简单,但这可能在Javascript中。我有像dis
这样的对象(数组)questions{
0:
{A:"A in index 0",
B:"B in index 0",
C:"C in index 0"
},
1:
{A:"A in index 1",
B:"B in index 1",
C:"C in index 1"
},
2:
{A:"A in index 2",
B:"B in index 2",
C:"C in index 2"
}
}
我如何做
之类的事情questions[0].A; //output : A in index 0
questions[2].B; //output : B in index 2
答案 0 :(得分:3)
你走了。你基本上需要将它分配给问题。
var questions = {
0: {
A: "A in index 0",
B: "B in index 0",
C: "C in index 0"
},
1: {
A: "A in index 1",
B: "B in index 1",
C: "C in index 1"
},
2: {
A: "A in index 2",
B: "B in index 2",
C: "C in index 2"
}
}
console.log(questions[0].A); //output : A in index 0
console.log(questions[2].B); //output : B in index 2
Jsfiddle:http://jsfiddle.net/basarat/8jVHg/