数组长度未定义 [英] Array length undefined
本文介绍了数组长度未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试获取多维数组的长度,如下所示,但是当我用alert()
测试它时,我却不确定.我想知道有多少项具有父数组(myArray),因为我想在循环i=0;i<myArray.length;i++
中使用它.
I'm trying to get the length of a multidimensional Array as follows, but when I test it with alert()
I get undefined. I would like to know how many items has the parent array (myArray), as I would like then to use it in a cycle i=0;i<myArray.length;i++
.
有什么想法吗?
myArray = array = {
'def':array = {
"first":"value",
},
0 : array = {
"T":"Some text",
},
1 : array = {
"T":"Some text",
},
};
leng = myArray.length;
alert(leng);
推荐答案
您可以使用数组语法创建数组:
You can create an array using array syntax:
array = ["first item", {second:'item'}, 3];
array.def = {something:"else"};
alert(array.length);
以下是使用数组数组创建多维数组的方法:
And here's how you create a multidimensional array using an array of arrays:
array = [
[1,2,3],
[4,5,6],
[7,8,9]
];
alert(array[0][2]); // alerts "3"
这篇关于数组长度未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文