-3

好的,这听起来可能很简单,但这在 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 
4

1 回答 1

2

干得好。您基本上需要将其分配给问题。

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/

于 2013-05-30T16:33:52.850 回答