Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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函数中从2d数组中检索值_Javascript_Arrays_Function - Fatal编程技术网

为什么我的数组读取零,在javascript函数中从2d数组中检索值

为什么我的数组读取零,在javascript函数中从2d数组中检索值,javascript,arrays,function,Javascript,Arrays,Function,我有一个生成2d数组的函数。但当我试图从2d数组中接收元素时,我会得到“未定义”。如何从函数中从2d数组中获取元素?我注意到,当数组中有明确的内容时,所有数组的读数都为零。如何更改 这里是代码 //The function prints the 2d array console.log(playerCal( 7, 5)); //Trying to access elements in the array var rec = playerCal(7 , 5); var

我有一个生成2d数组的函数。但当我试图从2d数组中接收元素时,我会得到“未定义”。如何从函数中从2d数组中获取元素?我注意到,当数组中有明确的内容时,所有数组的读数都为零。如何更改

这里是代码

//The function prints the 2d array 
console.log(playerCal( 7, 5));

    //Trying to access elements in the array
    var rec = playerCal(7 , 5);
    var print = rec[1][0];
    console.log(print);
阵列中显然有东西发生了什么


编辑把你的问题看错了,图像为我澄清了问题

在rec上执行console.log,而不是打印。根据您的图像,它表示print(设置为rec[1][0])是一个多维数组,具有print[1][0]的有效值


所以我认为rec并没有设置为您所认为的值。

我发现我不能在ajax中返回值。所以它返回零

如果您不正确地使用Ajax,其目的不是让它返回任何内容,而是将数据传递给一个称为回调函数的函数,该函数处理数据

function handleData( responseData ) {
    // do what you want with the data
    console.log(responseData);
}

$.ajax({
    url: "hi.php",
    ...
    success: function ( data, status, XHR ) {
        handleData(data);
    }
});

在submit处理程序中返回任何内容都不会起任何作用,相反,您必须将数据交给success函数,或者直接在success函数中对其执行所需操作。

您可以发布数组声明吗?这是什么意思?显示playerCal()中发生的情况会很有帮助函数,因为它显然是在传回一个结构与预期不同的数组。playCal()函数按图中所示打印数组,undefined是print变量。