Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 数组和要显示为字符串的变量_Javascript_Jquery_Arrays_String_Variables - Fatal编程技术网

Javascript 数组和要显示为字符串的变量

Javascript 数组和要显示为字符串的变量,javascript,jquery,arrays,string,variables,Javascript,Jquery,Arrays,String,Variables,我正在使用jquery,有两个名为的数组,question0AnswerTextArray和question1AnswerTextArray 这些数组中有字符串[“答案1的文本”,“答案2的文本”] 我还有一个名为quizQuestion的变量 我试图让文本显示如下: var tempBoxText = 'question'+quizQuestion+'AnswerTextArray['+answerNumber+']'; $('#quizTextBox').text(tempBoxText)

我正在使用jquery,有两个名为的数组,
question0AnswerTextArray
question1AnswerTextArray

这些数组中有字符串
[“答案1的文本”,“答案2的文本”]

我还有一个名为
quizQuestion
的变量

我试图让文本显示如下:

var tempBoxText = 'question'+quizQuestion+'AnswerTextArray['+answerNumber+']'; 
$('#quizTextBox').text(tempBoxText);
有什么想法吗?或者在JavaScript/jQuery中是否可以使用多维数组


谢谢你的建议。我最近刚开始使用JavaScript。

正如你已经提到的,更好的方法是使用数组数组:

var answers = [
    ["text for answer 1", "text for answer 2"],
    ["text for answer 1", "text for answer 2"]
];

$('#quizTextBox').text(answers[quizQuestion][answerNumber]);

我建议您阅读。

在JavaScript中可以使用多维数组。设置它们有点不同(但只是一个数组数组),检索值的语法如下:

var val = myArray[x][y];

x
y
可以作为您的问答索引。

感谢您的快速回复!这很有帮助!