jQuery的创建多维数组 [英] jQuery Create Multidimensional Array
本文介绍了jQuery的创建多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个时间试图找出如何在jQuery的一个多维数组赫克。
I am having a heck of a time trying to figure out how to create a multidimensional array in jQuery.
我实例环路以外的阵列。
I instantiate the array outside of the loop.
<script>
var myArray = [];
</script>
我的内循环我想添加的数组元素。
Inside of my loop I want to add the array elements.
i = 0
[loop start]
<script>
myArray[i][$row[sku]] = $row[qty]; // sku might be repeated will this cause an issue? You will see in the error below "295518" is repeated...
<script>
[loop end]
在我的源$ C $ C,它看起来是这样的:
In my source code it looks like this:
<script>
myArray[ 1 ][ 295518 ] = 122;
</script>
然后我运行这个在循环外底...
Then I run this at the end outside the loop...
<script>
console.log( myArray );
</script>
我得到在控制台这个错误:
I get this error in the console:
Uncaught TypeError: Cannot set property '295518' of undefined
Uncaught TypeError: Cannot set property '70252' of undefined
Uncaught TypeError: Cannot set property '295518' of undefined
我在做什么错在建立这个数组?谢谢!
What I am doing wrong in setting up this array? Thanks!
推荐答案
你可以这样做:
var a = [];
a[0] = [1,2,3];
a[1] = [4,5,6];
a[1][1] it is 5
这篇关于jQuery的创建多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文