an array, and a variable to display as a string
I'm using jquery and have two arrays with the names, question0AnswerTextArray and ques开发者_如何学Pythontion1AnswerTextArray.
Inside these arrays are strings ["text for answer 1", "text for answer 2"]
I also have a variable named quizQuestion.
I'm trying to get text to display like below:
var tempBoxText = 'question'+quizQuestion+'AnswerTextArray['+answerNumber+']';
$('#quizTextBox').text(tempBoxText);
Any ideas? Or are multidimensional arrays possible in JavaScript/jQuery?
Thanks for suggestions..I just started JavaScript recently.
As you already mentioned, a better way would be to use an array of arrays:
var answers = [
["text for answer 1", "text for answer 2"],
["text for answer 1", "text for answer 2"]
];
$('#quizTextBox').text(answers[quizQuestion][answerNumber]);
I recommend to read the MDN JavaScript Guide.
Multi-dimensional arrays are possible in JavaScript. Setting them up is a little different (but is just an array of arrays), and the syntax for retrieving values is like:
var val = myArray[x][y];
x and y can be your question and answer indices.
加载中,请稍侯......
精彩评论